This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Without marking transaction demarcation, just loading an entity through session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Without marking transaction demarcation, just loading an entity through session" Watch "Without marking transaction demarcation, just loading an entity through session" New topic
Author

Without marking transaction demarcation, just loading an entity through session

Krishnaa Kumar
Greenhorn

Joined: May 05, 2011
Posts: 25
What happens if I load an entity saying session.load() and close the session without beginning a transaction & comitting it
I gone through various sites, but couldn't find any good explanation.

Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

If i understood your question correctly, you want to know the effect of reading an entity without having any transaction. If so, then there is no adverse effect. Transactions are supposed to be used where you are making any kind of change in the database (like insert/update/delete operations). Just to read an Entity, transaction should not be used.
Krishnaa Kumar
Greenhorn

Joined: May 05, 2011
Posts: 25
Thanks for reply.

In the following post it says, if we access an entity in non-transactional way, we need to enable auto-commit in hibernate configuration.
If not, once we close the session (we used for retrieving the entity) the database connection returning to the pool will have some issues/memory leaks.

https://community.jboss.org/wiki/OpenSessionInView

lines in this link "the connection is in whatever mode it is by default after obtained from the pool, and returned there without commit or rollback. The behavior is then undefined."

kindly make me clear here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Without marking transaction demarcation, just loading an entity through session