在一个项目中,我们希望将hibernate版本从3.6升级到4.3。
在hibernate 3中,我们使用AnnotationSessionFactoryBean:
<bean id="AbstractSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
abstract="true">
<!-- <property name="packagesToScan" value="com.amazon.layout.dao.model" /> -->
<property name="annotatedClasses">
<list>
<value>com.amazon.layout.dao.model.EdgeModel</value>
<value>com.amazon.layout.dao.model.VertexModel</value>
<value>com.amazon.layout.dao.model.PhysicalResourceToVertexMappingModel</value>
</list>
</property>
<property name="exposeTransactionAwareSessionFactory">
<value>true</value>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory" />
</bean>
<!-- Use Spring transactions for Hibernate -->
<tx:annotation-driven transaction-manager="txManager" mode='aspectj' proxy-target-class='true' />
</beans>
在hibernate 4.3中,我们使用LocalSessionFactoryBean:
<bean id="AbstractSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
abstract="true">
<!-- <property name="packagesToScan" value="com.amazon.layout.dao.model" /> -->
<property name="annotatedClasses">
<list>
<value>com.amazon.layout.dao.model.EdgeModel</value>
<value>com.amazon.layout.dao.model.VertexModel</value>
<value>com.amazon.layout.dao.model.PhysicalResourceToVertexMappingModel</value>
</list>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory" />
</bean>
<!-- Use Spring transactions for Hibernate -->
<tx:annotation-driven transaction-manager="txManager" mode='aspectj' proxy-target-class='true' />
</beans>
答案 0 :(得分:0)
来自LocalSessionFactoryBean
的javadoc:
此类的作用与orm.hibernate3包中的同名类相似。但是,在实践中,它更接近AnnotationSessionFactoryBean,因为它的核心目的是从包扫描中引导SessionFactory。
LocalSessionFactoryBean
未公开该方法的原因是它不必要。