The mapping file is configured in spring Applicationcontext.xml, typically in the bean instance of <sessionFactory>, if the mapping file is configured to be small, You can use the "mappingresources" property of the Sessionfactory class Localsessionfactorybean, including (Mappingresources,mappinglocations, Mappingdirectorylocations and Mappingjarlocations) define the following methods:
The first type:
<property name= "Mappingresources" >
<list>
<value>com/w3cs/vlar/hibernate/Person.hbm.xml</value>
<value>com/w3cs/vlar/hibernate/Car.hbm.xml</value>
<value>com/w3cs/vlar/hibernate/Engine.hbm.xml</value>
<value>com/w3cs/vlar/hibernate/Toy.hbm.xml</value>
</list>
</property>
As configuration files become more and more cumbersome to read and modify, and XML-based configuration can lead to input errors, you may be wasting half a day searching for errors because of a single character error.
The second type:
In this case, you can use the Localsessionfactorybean "Mappingdirectorylocations" property to define the mapping file, as long as you indicate the folder where the map file is located, Spring will find out all the mapping files in that folder for you, as defined by the following:
<property name= "Mappingdirectorylocations" >
<list>
<value>WEB-INF/mappings</value>
</list>
</property>
The third type:
Of course, its property values can also be indicated by Classpath, at which point the class path of the project is specified
<property name= "Mappingdirectorylocations" >
<list>
<value>classpath:/my/package/*.hbm.xml</value>
</list>
</property>
The fourth type:
<!--added processing configuration for large object fields begin-->
<bean id = "Oraclelobhandler"
class = "Org.springframework.jdbc.support.lob.OracleLobHandler"
Lazy-init = "true" >
<property name = "NativeJdbcExtractor" ref = "NativeJdbcExtractor"/>
</bean>
<bean id = "NativeJdbcExtractor" class = " Org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor "
Lazy-init = "true"/>
<!--increased processing of large object fields configure end-->
<!--define the Sesscionfactory objects required in the Hibernatte framework//-->
<bean id= "Sessionfactory"
class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<!--increased processing configuration of large object fields Begin--
<property name = "Lobhandler" ref = "Oraclelobhandler"/>
<!--added to large object field processing configuration End--
<property name= "Mappingdirectorylocations" >
<list>
<value>classpath:/my/package/login/dao/pojo/</value>
<value>classpath:/my/package/jpf/dao/pojo/</value>
......
</list>
</property>
Spring loading Hibernate mapping files in several ways (go)