Spring loading Hibernate mapping files in several ways (go)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.