• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

disabling autoCommit in hibernate

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oracle 10 g
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic