天天看点

Spring+Hibernate配置hbm.xml文件在jar文件中。

有时候,hbm文件被打包到jar文件中,按照网上文章配置总报错,如下:

Caused by: org.hibernate.InvalidMappingException: Could not read mapping documents from jar: cidbcommon.jar

自己反复测试,正确配置应该如下:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="mappingJarLocations">

<list>

<value>classpath:cidbcommon.jar</value>

</list>

</property>

<property name="hibernateProperties">

<value>

hibernate.dialect=com.platform.ci.gui.db.util.OracleDialect

hibernate.hbm2ddl.auto=none

hibernate.show_sql=false

hibernate.format_sql=false

</value>

</property>

</bean> 

也就是说配置了 mappingJarLocations, 就不能再配置 mappingLocations 了,切记。