一尘不染

没有xml的spring + hibernate映射类

hibernate

在我的applicationContext.xml中,这就是将xml映射到POJO的方式。如何将目录映射到类文件而无需创建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>

阅读 171

收藏
2020-06-20

共1个答案

一尘不染

您可以通过转换进一步简化操作

<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现在您@Entitycom.mycompany.sample.domain包中所有带有注释的类都将自动被拾取。

2020-06-20