*
The moose likes Object Relational Mapping and the fly likes disabling autoCommit in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "disabling autoCommit in hibernate" Watch "disabling autoCommit in hibernate" New topic
Author

disabling autoCommit in hibernate

Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
hello ranchers,
Can any one let me me know how do i disable auto commit when using hibernate. and commit explicitly after all my transaction is successfully other wise rollback...


any help would be appreciated.


Thanks in advance.


Java Dev User
Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
set the property connection.autocommit to false as below

<property name="hibernate.connection.autocommit">false</property>

and using a transaction if every thing went right then you can commit the transaction.


Ram Parashar
http://doinfinite.com
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
<property name="hibernate.connection.autocommit">false</property>


This is fine...but then how will i commit my transaction ..if every thing went right .. i went through the functions of getHibernateTemplate .But didnot find anything for commit();

Can you please post a small example for the same.
tabiul mahmood
Greenhorn

Joined: Sep 17, 2009
Posts: 18
session.getTransaction().commit. Here the session is your Hibernate Session that you can get from SessionFactory
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
i did added that property ...

but still it was commiting the record...

i just added the
<property name="hibernate.connection.autocommit">false</property>


and normally went for saving...
this mean ,unless i do an explicit commit i will not be able the new record which is inserted.

but i was able to see the new record.

wat else need to be done ...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What database are you using? Does it support transactions?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
oracle 10 g
Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
It seems as if you are using Spring (Hibernate template).
HibernateTemplate has inbuilt mechanism which will definitely save the object. (Callback methods are taking care for all this.)
If you really want to see the effect then use your own transaction using HIbernate Session and then dont commit that, you can see the effect.

Ritika Misra
Ranch Hand

Joined: Jun 17, 2009
Posts: 30
you mean to say ...instead of using hibernateTemplate ...i should go for using traditional method for starting of a new transacation and then execute the query and the explicit commit...

When i use hibernate template ..cant this be achived .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: disabling autoCommit in hibernate