• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

when is Transaction used in hibernate?

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am new to hibernate, I was trying out some code, nothing gets written to the database. However if I surround my code inside begintransaction and commit, it works fine. So my question is, should most operations be done inside transaction? Or when should the transaction be used?
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to your first schooling in Hibernate.

The word transaction can be literally defined as a "unit of work." Is connecting to a database, querying its data, and getting back some information work? I'm sure the database would think so.

So yes, you always need a transaction. You are always doing work.

Now, when we think of transactions, we often think of the ACID properties of a transaction, and rolling things back, and commits, and stuff like that, and you certainly don't need all that with a read, or something simple, but that doesn't mean you're not transacting with the database.

So yes, you always need a transaction.

A person named Christian Bauer, someone who might know a little bit about Hibernate, wrote this about your very question:

I did a training two weeks ago and all 12 people said "No" when I asked "are database transactions mandatory?". We have a long way...



Do We Always Need A Transaction?



Tutorial: How to Save Data to the Database Using Hibernate and JPA

-Cameron McKenzie
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic