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.  [ 1 post ] 
Author Message
 Post subject: Transaction.rollback() and
PostPosted: Mon Jan 31, 2005 1:15 pm 
Newbie

Joined: Mon Dec 20, 2004 11:53 am
Posts: 8
Hi,

I have a question regarding the way tx.rollback() works. In the following code, I create a new message and it persists to the database when I commit. In the second transaction I change the value and then roll back, so it doesn't save the change to the database. What I'm looking for is to restore the message object back to the original value before the transaction started. Anyone know of a good way to do that in the same session, without doing another select?

Code:
        Session s = sessions.openSession();

        Transaction tx = s.beginTransaction();
        Message m = new Message("This message should persist!");
        try {
            s.saveOrUpdate(m);
        } finally {
            tx.commit();
        }

        tx = s.beginTransaction();
        try {
            m.setText("This message is transient!");
            s.saveOrUpdate(m);
        } finally {
            tx.rollback();
        }
        // m still has the 'rolled back' value at this point
        s.close();


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

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.