根据文档(Spring
docs),它仅仅是元数据,它表明方法或接口可以由“具有交易意识的”事物(例如
<tx:annotation-driven/>)进行配置。
相信只有 tx:annotation驱动 并且没有
@Transactional属性,我相信您可以应用“默认”事务性:
- 传播设置是 必需的 。
- 隔离级别为 DEFAULT 。
- 事务是读/写。
- 事务超时默认为基础事务系统的默认超时,如果不支持超时,则默认为无。
- 任何 RuntimeException都会 触发回滚,而任何选中的 Exception 都不会触发。
假设您使用的
<tx:annotation-driven />是通过事务管理器来驱动它,那么缺少该
@Transactional属性意味着您无法应用诸如
readOnly , isolation , propagation , propagation , rollbackFor ,
noRollbackFor 等 属性 。
我相信MVC稍有不同-Hibernate会话直接与MVC请求绑定-即,当收到请求时,事务开始。
回到您的示例,HibernateDAOSupport中的getSession()的代码如下:
protected final Session getSession() throws DataAccessResourceFailureException, IllegalStateException { return getSession(this.hibernateTemplate.isAllowCreate());}依次调用:
protected final Session getSession() throws DataAccessResourceFailureException, IllegalStateException { return getSession(this.hibernateTemplate.isAllowCreate());}最终要求:
private static Session doGetSession( SessionFactory sessionFactory, Interceptor entityInterceptor,SQLExceptionTranslator jdbcExceptionTranslator, boolean allowCreate)
从根本上讲,Transaction:Session绑定为1:1
AFAIK,并且没有事务运行的唯一方法是使用说JBoss,它具有“嵌入”持久层,为您(在幕后)提供了事务性。即使您在调用
getQuery()之后
getSession()仍然有效地发生了事务,因为它是JDBC
/ Hibernate连接。



