Properties Mappinglocations, mappingdirectorylocations in spring configuration file
Source: Internet
Author: User
Since spring's integration of Hibernate profile hibernate.cfg.xml is fairly good,
So, in my project, I've been using Spring's org.springframework.orm.hibernate.LocalSessionFactoryBean to replace the functionality of the Hibernate.cfg.xml file.
Localsessionfactorybean has several properties to look up hibernate mapping files: mappingresources, Mappinglocations, Mappingdirectorylocations and Mappingjarlocations
The difference between them:
Mappingresources: Specify the specific mapping file name under Classpath
<property name= "Mappingresources" >
<value>petclinic.hbm.xml </value>
</property>
Mappinglocations: You can specify any file path, and you can specify a prefix: classpath, file, and so on
<property name= "Mappinglocations" >
<value>/web-inf/petclinic.hbm.xml </value>
</property>
<property name= "Mappinglocations" >
<value>classpath:/com/company/domain/petclinic.hbm.xml </value>
</property>
You can also specify by using a wildcard character, ' * ' to specify a file (path) name, ' * * ' to specify multiple file (path) names, for example:
<property name= "Mappinglocations" >
<value>classpath:/com/company/domainmaps/*.hbm.xml </value>
</property>
The above configuration is the Hbm.xml file under any maps path under the Com/company/domain package is loaded as a mapping file
Mappingdirectorylocations: Specifies the mapped file path
<property name= "Mappingdirectorylocations" > <list>
<value>WEB-INF/HibernateMappings</value>
</list>
</property>
You can also use Classpath to point out
<property name= "Mappingdirectorylocations" >
<list>
<value>classpath:/XXX/package/</value>
</list>
</property>
Mappingjarlocations: Specifies that the loaded mapping file is in the jar file
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.