Topic: 超奇怪!我用hibernate连sqlserver可以查询,但不能更新?

  Print this page

1.超奇怪!我用hibernate连sqlserver可以查询,但不能更新? Copy to clipboard
Posted by: wuliang
Posted on: 2004-09-12 11:25

session.delete("from MobileSpecific");
session.flush();
执行这个语句,结果数据库没有记录被删,mobile_specific是个很简单的表,没有外键什么的,

console没有输出任何异常,sqlserver那边,用 事件探查器 跟踪到
exec sp_executesql N'delete from mobile_specific where id=@P1', N'@P1 int ', 1
... N'@P1 int ', 2
应该说明查询提交到数据库了,但mobile_specific表没有记录被删?!~

将hibernate.cfg.xml里换成mysql能成功删除,似乎不是程序问题?
用jdbc方式直接写sqlserver也可以删除,说明不是jdbc驱动问题??
... cn = DriverManager.getCon...
stm.executeUpdate("delete mobile_specific");
另外一个hibernate+sql server+tomcat的例子能删除数据,说明不是数据库的问题???

想不通,
xp + sp2
sql server 2000 + sp3
hibernate 2.1.6
ms sql server jdbc + sp1

有谁碰到过这么奇怪的问题?要疯掉了~~~

2.Re:超奇怪!我用hibernate连sqlserver可以查询,但不能更新? [Re: wuliang] Copy to clipboard
Posted by: wuliang
Posted on: 2004-09-13 22:11

问题解决了,是autocommit的问题,autocommit=false时,session.close导致sql server回滚,
但mysql里,同样的情况更新却保存了,数据库行为不同导致了不同的结果

缺省DriverManager.getConnection()得到的连接,autocommit是true的,
hibernate带的两个连接池DriverManagerConnectionProvider
C3P0ConnectionProvider
的getConnection()方法,从pool里返回前都有一句:
if ( c.getAutoCommit() ) c.setAutoCommit(false);

不知道是不是所有的连接池都返回autocommit=false的connection

3.Re:超奇怪!我用hibernate连sqlserver可以查询,但不能更新? [Re: wuliang] Copy to clipboard
Posted by: eric_dasini
Posted on: 2004-09-14 11:53

请致电13501130725, 找苏毅

4.Re:超奇怪!我用hibernate连sqlserver可以查询,但不能更新? [Re: wuliang] Copy to clipboard
Posted by: vruser
Posted on: 2004-09-24 13:09

我也遇到过类似的问题,最后代码上改用事务的方式解决的


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923