spring + hibernate映射类,不带xml [英] spring+hibernate mapping class without xml
本文介绍了spring + hibernate映射类,不带xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的applicationContext.xml中,这是我将xml映射到POJO的方式。如何将目录映射到类文件而不需要创建xml?
in my applicationContext.xml, this is how I map xml to POJO. how to map directory to class file without required to create xml?
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/custompackage/custom/spi/hibernate3/HibernateCurrentStep.hbm.xml</value>
<value>com/custompackage/custom/spi/hibernate3/HibernateHistoryStep.hbm.xml</value>
<value>com/custompackage/custom/spi/hibernate3/HibernatecustomEntry.hbm.xml</value>
<value>user/custom/hibernate3/PropertySetItemImpl.hbm.xml</value>
<value>com/custompackage/user/provider/hibernate3/user/impl/HibernateGroupImpl.hbm.xml</value>
<value>com/custompackage/user/provider/hibernate3/user/impl/HibernateUserImpl.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
.....
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
推荐答案
>
And you can further simplify things by converting
<property name="annotatedClasses">
<list>
<value>com.mycompany.sample.domain.Order</value>
<value>com.mycompany.sample.domain.LineItem</value>
...
</list>
</property>
至
<property name="packagesToScan" value="com.mycompany.sample.domain" />
在 AnnotationSessionFactoryBean
所以现在所有类注释 com.mycompany.sample.domain
包中的 @Entity
会被自动提取。
in your AnnotationSessionFactoryBean
so now all classes annotated with @Entity
in the com.mycompany.sample.domain
package will be automatically picked up.
这篇关于spring + hibernate映射类,不带xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文