• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate: couldn't turn off autocommit

 
will zhang
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate doesn't autocommit unless you tell it to. Which storage engine are you using? Not all MySQL engines support transactions.
 
will zhang
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic