好像是Session有问题,但又不知道如何解决
解决方案 »
- 配置SSH下的C3P0数据源
- hibernate和数据库断开连接问题
- 开发一套象SoGou地图这样的系统大概需要多少钱?
- 怎样使用Tomcat服务器,在外网注册域名,站点都已建好,请各位同人支持,谢谢
- javaEE hql多表查询求大师指导
- 菜鸟送分问题,up有分!
- 现在在那还可以下载到 openorb 啊!
- j2ee开发:开发环境的选择问题
- 请教一个SOAP的问题。
- web.xml配置中,Classpath:com/.../spring-context.xml怎样取得其文件流
- axis java客户端调用.net的webservice无法识别请求元素
- 关于Spring事务控制的困扰,高手请进!
2.你可以在配置文件中配置上事务处理的相关内容,那样就不需要在程序中进行明码的事务处理啦
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
autowire="byName" />
<bean id="matchAllWithPropReq"
class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
<property name="transactionAttribute">
<value>PROPAGATION_REQUIRED</value>
</property>
</bean>
<bean id="matchAllTxInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributeSource">
<ref bean="matchAllWithPropReq" />
</property>
</bean>
另外查询不需要事务处理的话,那么在后续的操作还是需要事务的,比如插入。
我想这个问题并不是因为使用事务而出的错,主要还是Session使用时有问题。我用断点跟踪了一下,发现是DBOperate.java里的这一句List list = q.list();抛出的错误。
还请各位帮助找到真正的问题
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
throw e;
}
应该加入
finally {
HibernateUtil.closeSession();
}