File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes why to use session.beginTransaction & transaction.commit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "why to use session.beginTransaction & transaction.commit" Watch "why to use session.beginTransaction & transaction.commit" New topic

why to use session.beginTransaction & transaction.commit

Krishnaa Kumar

Joined: May 05, 2011
Posts: 25
If any Transient object was added into hibernate session, why can't hibernate persist it(after its dirty checking) when i close the session. Is there any such of kind of option available.
Also, if such option exists, then why we are beginning a transaction & saying it to commit. (session.beginTransaction() )

what functionality that transaction.commit() does can also be done once we say session.close() right?
Kindly any one explain me about this.

thanks in advance.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

If you don't want to write code to begin & end transaction, you can use Spring & have annotation based transactions . but in that case Spring will handle starting & ending the transactions. i know i didn't answer your "why" part, i apologize for that.
It is sorta covered in the JavaRanch Style Guide.
subject: why to use session.beginTransaction & transaction.commit
Similar Threads
InitialContext did not implement EventContext
simulating select for update in hibernate.
jboss transactions and hibernate
update problem
session.flush() vs. transaction.commit()