Java – hibernate spring MVC: object mapping configuration
•
Java
Is there any way to define hibernate by scope instead of one by one cfg. Objects in XML?
For example, in spring, you can define all controllers through the following annotations:
<context:component-scan base-package="crm.controller" />
Can I define hibernate classes in the same way? Or must we define them one by one?
thank you
Solution
If spring MVC is used, it can be configured when setting sessionfactory If you are using HBM files:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSession@R_502_764@"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>file1.hbm.xml</value> <value>file2.hbm.xml</value> </list> </property> <property name="hibernateProperties" ref="hibernateProperties"/> </bean>
If you use annotation classes:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSession@R_502_764@"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.me.domain"> <property name="hibernateProperties" ref="hibernateProperties"/> </bean>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码