• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disabling autoCommit in hibernate

 
Ritika Misra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ritika Misra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.getTransaction().commit. Here the session is your Hibernate Session that you can get from SessionFactory
 
Ritika Misra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database are you using? Does it support transactions?
 
Ritika Misra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oracle 10 g
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic