File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate: couldn't turn off autocommit Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "hibernate: couldn Watch "hibernate: couldn New topic
Author

hibernate: couldn't turn off autocommit

will zhang
Ranch Hand

Joined: Sep 11, 2008
Posts: 46
I'm using hibernate annotations, my database in is MySQL5.0.

I tried to persist a bunch of objects and commit at the end, which means insert all or insert none of them.
For example, I want to insert 10 objects one time, if exception happens at the 9th object, because I didn't do commit, there should be no new data in database. However, I do find the 8 datas. Anyone has experience/solution for this?

BTW, I didn't use Spring. I also used rollback but doesn't work.

The thing is like my save() already commit the transaction without closing the session.



Here's some of my hibernation configuration:

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hibernate doesn't autocommit unless you tell it to. Which storage engine are you using? Not all MySQL engines support transactions.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
will zhang
Ranch Hand

Joined: Sep 11, 2008
Posts: 46
Paul Sturrock wrote:Hibernate doesn't autocommit unless you tell it to. Which storage engine are you using? Not all MySQL engines support transactions.


Thanks for reply. But how to check storage engine?

BTW, We have another project which has exactly the same setting as this one. However, autocommit is off on that project, even if I turn it on.

In other words, in project A, autocommit is on regardless of my setting config.setProperty("hibernate.connection.autocommit", "false");

in project B, autocommit is off regardless of my setting config.setProperty("hibernate.connection.autocommit", "true");

It seems config.setProperty("hibernate.connection.autocommit", "false/true"); doesn't do its job at all.
 
 
subject: hibernate: couldn't turn off autocommit
 
Threads others viewed
InitialContext did not implement EventContext
jdbc connections not closing
Problems with .sql(script files) and .properties files. [Using Netbeans]
Oracle Sequence
Hibernate: flush() does not commit to database
IntelliJ Java IDE