http://www.52itstyle.com/thread-513-1-1.html
spring注解hibernate实体类
<property name="annotatedClasses">
<list>
<value>com.sise.domain.Admin</value>
<value>com.sise.domain.Remind</value>
<value>com.sise.domain.User</value>
</list></property>
可以用
<property name="packagesToScan" value="com.sise.domain"/>
代替;
-----------------------------------------------------------------------------------------------------------------------
事务:
<tx:annotation-driven transaction-manager="txManager" />
这句声明表示可以用@Transactional标签管理事务,但是需要在每个方法或者类后面去标注;
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="leePointcut"
expression="execution(* com.demo.hibernate.service.*Impl.*(..))" />
<!-- 指定在txAdvice切入点应用txAdvice事务切面 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="leePointcut" />
</aop:config>
而这种方法可以将事务统一配置到service层
------------------------------------------------------------------------------------
不认aop标签时,引入
xmlns:aop="http://www.springframework.org/schema/aop "
本文详细介绍了如何使用Spring注解和Hibernate实体类进行事务管理,包括配置annotatedClasses、packagesToScan,以及如何通过事务注解和AOP实现对不同操作的事务控制。同时,展示了在service层统一配置事务的方法。
719

被折叠的 条评论
为什么被折叠?



