-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate transactions question
PostPosted: Sun Mar 26, 2006 3:12 pm 
Newbie

Joined: Sun Mar 26, 2006 3:04 pm
Posts: 6
I have a question about the transactions in Hibernate that the documentation was not able to answer

Suppose I have a code like the one given below

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);

session.save(theEvent);


Suppose I did NOT explicitly say session.beginTransaction() and session.getTransaction().commit(); or flush(). When would the session.save() take effect (persist to the database)?

In the documentation it says all hibernate actions happen within a transaction. Does this mean hibernate would automatically start a transaction even if you do not explictly declare one (as is the case in pseudo-code given above)

Thanks much
DuKot


Top
 Profile  
 
 Post subject: my bad
PostPosted: Sun Mar 26, 2006 3:45 pm 
Newbie

Joined: Sun Mar 26, 2006 3:04 pm
Posts: 6
Looks like I will get a runtime error if I do not explicitly start a transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 5:51 pm 
Beginner
Beginner

Joined: Sun Feb 19, 2006 3:50 am
Posts: 34
Correct. The session.save(theEvent) must happen within a transaction. The database will not be modified until the transaction commit however. The session.save() call ony prepares the modifications, while the transaction commit takes those modifications and makes them happen in the database, but the session.save() call still has to have an open transaction to work with.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.