quot;org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/>
<!-- 对所有继承 BaseService类的公用方法实施事务增强 -->
<aop:config proxy-target- class="true">
<aop:pointcut id="serviceJdbcMethod"
expression="within(user.mixdao.BaseService+)"/>
<aop:advisor pointcut-ref="serviceJdbcMethod"
advice-ref="hiberAdvice"/>
</aop:config>
<tx:advice id="hiberAdvice" transaction- manager="hiberManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
启动 Spring 容器,执行 UserService#logon() 方法, 可以查看到如下的执行日志:
清单 5. 代码运行日志
12:38:57,062 (AbstractPlatformTransactionManager.java:365) - Creating new transaction
with name [user.mixdao.UserService.logon]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
12:38:57,093 (SessionImpl.java:220) - opened session at timestamp: 12666407370
12:38:57,093 (HibernateTransactionManager.java:493) - Opened new Session
[org.hibernate.impl.SessionImpl@83020] for Hibernate transaction ①
12:38:57,093 (HibernateTransactionManager.java:504) - Preparing JDBC Connection
of Hibernate Session [org.hibernate.impl.SessionImpl@83020]
12:38:57,109 (JDBCTransaction.java:54) - begin
…
logon method...
updateLastLogonTime...
…
12:38:57,109 (AbstractBatcher.java:401) - select user0_.USER_NAME as USER1_0_0_,
user0_.LAST_LOGON_TIME as LAST2_0_0_, user0_.password as password0_0_,
user0_.score as score0_0_ from T_USER user0_ where user0_.USER_NAME=?
Hibernate: select user0_.USER_NAME as USER1_0_0_,
user0_.LAST_LOGON_TIME as LAST2_0_0_, user0_.password as password0_0_,
user0_.score as score0_0_ from T_USER user0_ where user0_.USER_NAME=?
…
12:38:57,187 (HibernateTemplate.java:422) - Not closing pre-bound
Hibernate Session after HibernateTemplate
12:38:57,187 (HibernateTemplate.java:397) - Found thread-bound Session
for HibernateTemplate
Hibernate: update T_USER set LAST_LOGON_TIME=?, password=?, score=? where USER_NAME=?
…
2010-02-20 12:38:57,203 DEBUG [main] (AbstractPlatformTransactionManager.java:470)
- Participating in existing transaction ②
addScore...
2010-02-20 12:38:57,203 DEBUG [main] (JdbcTemplate.java:785)
- Executing prepared SQL update
2010-02-20 12:38:57,203 DEBUG [main] (JdbcTemplate.java:569)
- Executing prepared SQL statement
[UPDATE t_user u SET u.score = u.score + ? WHERE user_name =?]
2010-02-20 12:38:57,203 DEBUG [main] (JdbcTemplate.java:794)
- SQL update affected 1 rows
激活连接数量:1 ③
2010-02-20 12:38:57,203 DEBUG [main] (AbstractPlatformTransactionManager.java:752)
|