beans.xml配置多个hbm.xml

本文介绍如何在Spring配置文件中使用mappingDirectoryLocations属性简化Hibernate的*.hbm.xml映射文件管理,提高项目开发及维护效率。
java开源框架应用技巧之spring配置文件中如果有多个.hbm.xml文件的话,无论是项目开发过程中还是维护过程中修改起来都会很麻烦切容易出错 收藏
问题描述:
在spring配置文件中如果有多个*.hbm.xml文件的话,无论是项目开发过程中还是维护过程中修改起来都会很麻烦切容易出错
这时我们可以把name="mappingResources"改为name="mappingDirectoryLocations",然后只需要配置*.hbm.xml文件所在目录就行了


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--<property name="mappingResources">
<list>
<value>classpath:/com/crm/entity</value>
<value>com/crm/entity/BasDict.hbm.xml</value>
<value>com/crm/entity/CstActivity.hbm.xml</value>
<value>com/crm/entity/CstCustomer.hbm.xml</value>
<value>com/crm/entity/CstLinkman.hbm.xml</value>
<value>com/crm/entity/CstService.hbm.xml</value>
<value>com/crm/entity/SalChance.hbm.xml</value>
<value>com/crm/entity/SalPlan.hbm.xml</value>
<value>com/crm/entity/SysRight.hbm.xml</value>
<value>com/crm/entity/SysRole.hbm.xml</value>
<value>com/crm/entity/SysRoleRight.hbm.xml</value>
<value>com/crm/entity/SysUser.hbm.xml</value>
<value>com/crm/entity/VOrders.hbm.xml</value>
<value>com/crm/entity/VOrdersLine.hbm.xml</value>
<value>com/crm/entity/VProduct.hbm.xml</value>
<value>com/crm/entity/VStorage.hbm.xml</value>
</list>
</property>-->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/crm/entity</value>
</list>
</property>
<property name="hibernateProperties">
<value>
<!-- hibernate.dialect=org.hibernate.dialect.MySQLDialect -->
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.hbm2dll.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值