Two ways to configure Hibernate mapping files using spring

Source: Internet
Author: User

There are two ways to configure Hibernate mappings in spring to implement the

1: When the required mapping file is less, can be implemented by mappingresources

The specific implementation is as follows:

<property name= "Mappingresources" > <list> <value>com/yourcompany/model/teacher.hbm.xml</ Value> <value>com/yourcompany/model/Student.hbm.xml</value> <value>com/yourcompany/model/ School.hbm.xml</value> </list> </property>

The main thing is to use <value> </value> to list the location and name of your mapping file in <list></list>.

The advantages of this realization: more intuitive, easy to understand, the drawback is: if the mapping file too much, one is too much repetition of code, the second is if there is a wrong place to find.

So we can use the following method, just give spring a folder, other things, let Spring do.

2: When there are too many files to map, we can use: Mappingdirectorylocations to implement

Specific as follows:

You can specify or change the Classpath:/com/yourcompany to a folder location by Classpath: web-inf/modelmappings

<property name= "Mappingdirectorylocations" > <list> <value>classpath:/com/yourcompany/model/< /value> </list> </property>

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.