Spring整合Hibernate4與Hibernate3的幾個小細節

1.在Spring3中如果Hibernate實體類是採用XML文件配置的,配置SessionFactory需要使用LocalSessionFactoryBean,@註解配置的使用類用AnnotationFactoryBean其餘的沒有區別,但是在Spring4中必須統一使用LocalSessionFactoryBean來配置SessionFactory

2.配置事務屬性時,Hibernate4必須配置爲開啓屬性,否則getCurrentSession()獲取不到如下:

<!-- 配置事務屬性 -->
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<!--hibernate4必須配置爲開啓事務 否則 getCurrentSession()獲取不到-->
			<tx:method name="find*" read-only="true" propagation="REQUIRED" />
			<tx:method name="list*" read-only="true" propagation="REQUIRED" />
			<tx:method name="get*" read-only="true" propagation="REQUIRED" />
			<tx:method name="count*" read-only="true" propagation="REQUIRED" />
			<!-- 其他方法在事務中運行 -->
			<tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="del*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章