-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transactions vs plain Flush()
PostPosted: Fri Apr 07, 2006 2:40 pm 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
I have an object I need to save after updating it. I wanted to know what is better. This:

Code:
        public static void Save(Entidad o)
        {
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
            session.SaveOrUpdate(o);
            transaction.Commit();
            session.Close();
        }


or this:

Code:
        public static void Save(Entidad o)
        {
            ISession session = factory.OpenSession();
            session.SaveOrUpdate(o);
            session.Flush();
            session.Close();
        }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 6:05 am 
Newbie

Joined: Mon Apr 10, 2006 5:21 am
Posts: 2
Location: Amsterdam
Generally speaking, updating the object from within a transaction is preferable, because when a problem occurs, all modifications to the database since starting the transaction would be reverted.

If you are not using a transaction, and a Save or Update generates an exception, any save's that preceded the exception would stay in the database, but the ones that follow would not get through. This would almost surely cause inconsistent data.

Since you do not really know what kind of updates a Save() causes (certainly not with lifecycle objects and cascades) this is actually quite dangerous. So my advice would be: use transactions and read section 10.5 in the Hibernate documentation (version 2.1.7)!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.