Spring integrates Hibernate ing files in four ways,
Summary:
In Spring applicationContext. the Hibernate ing file is integrated in xml, usually in the <sessionFactory> Bean instance. If there are few ing files configured, you can use the "mappingResources" attribute of LocalSessionFactoryBean, which belongs to sessionFactory. However, using the "mappingResources" attribute is not the only choice. Other equivalent options include mappingLocations, mappingDirectoryLocations, and mappingJarLocations)
An example of configuring a sessionFactory is as follows:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="hotelSysDS" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>/edu/fjnu/hotelsys/domain/User.hbm.xml</value> <value>/edu/fjnu/hotelsys/domain/Hotel.hbm.xml</value> <value>/edu/fjnu/hotelsys/domain/Room.hbm.xml</value> </list> </property> </bean>
Directory: mappingResources
MappingResources: Specifies the specific clasing file name under classpath.
Method 1:
<property name="mappingResources" value=“userTest.hbm.xml”/>
Method 2:
<property name="mappingResources"> <value>petclinic.hbm.xml </value> </property>
Method 3: Use list to specify multiple ing files at the same time
<property name="mappingResources"> <list> <value>/edu/fjnu/hotelsys/domain/User.hbm.xml</value> <value>/edu/fjnu/hotelsys/domain/Hotel.hbm.xml</value> <value>/edu/fjnu/hotelsys/domain/Room.hbm.xml</value> </list></property>
As the number of configuration files increases, reading and modification becomes more and more troublesome, and XML-based configuration may also cause input errors, as a result, you may waste half a day searching for errors due to a character error.
Note: The configuration methods will not be listed one by one below
MappingLocations
MappingLocations: You can specify any file path.
<property name="mappingLocations"> <value>/WEB-INF/petclinic.hbm.xml </value> </property>
Or specify the prefix: classpath, file, etc.
<property name="mappingLocations"> <value>classpath:/com/company/domain/petclinic.hbm.xml </value> </property>
You can also specify a file (PATH) name with a wildcard character. '*' specifies multiple file (PATH) names. For example:
<property name="mappingLocations"> <value>classpath:/com/company/domainmaps/*.hbm.xml </value> </property>
The above configuration is that all hbm. xml files under the com/company/domain package are loaded as ing files.
MappingDirectoryLocations
MappingDirectoryLocations: Specifies the mapped file path.
<property name="mappingDirectoryLocations"> <list> <value>WEB-INF/HibernateMappings</value> </list></property>
You can also use classpath to specify
<property name="mappingDirectoryLocations"> <list> <value>classpath:/XXX/package/</value> </list></property>
MappingJarLocations
MappingJarLocations: Specifies the loaded ing file in the jar file.