Spring和Hibernate:将cfg.xml加载到应用程序上下文中

时间:2013-03-26 13:54:17

标签: spring hibernate

datasource.hibernate.cfg.xml有hiberanteProperties和所有映射资源。
但是现在我必须分别在applicationContext.xml中定义映射资源和属性 我可以在configLocation中将datasource.hibernate.cfg.xml指定为<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">并删除mappingResources and hibernateProperties。现在我的应用程序上下文如下所示:

<property name="mappingResources"/>
            <list>
                <value>../../src/editsolutions.hibernate.cfg.xml</value>
            </list>
        <property name="hibernateProperties"> 
           <props> 
           <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
           <prop key="hibernate.connection.isolation">3</prop> 
           <prop key="hibernate.current_session_context_class">jta</prop> 
           <prop key="hibernate.transaction.factory_class"> 
               org.hibernate.transaction.JTATransactionFactory 
           </prop> 
           <prop key="hibernate.transaction.manager_lookup_class"> 
              com.atomikos.icatch.jta.hibernate.TransactionManagerLookup 
           </prop> 
           </props>
        </property> 

注意:我不对实体类使用注释。这是一个遗留项目,所有内容都是通过hbm.xml定义的。

1 个答案:

答案 0 :(得分:1)

您可以设置'configLocation'属性并删除其他属性。 See