-->
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: transaction become inactive by ConstraintViolationException
PostPosted: Fri Dec 03, 2010 8:33 am 
Newbie

Joined: Fri Dec 03, 2010 5:08 am
Posts: 2
After a ConstraintViolationException when trying to delete an entity, the transastion become inactive so I can't make a rollback ands session.clear() close my session

I work with permenant session
Code:
try {
            tx.begin();
           
            deleteObject(template, errorMessage, getSession());

            tx.commit();
        } catch (Exception ex) {
            logger.error("Unable to delete allocation template: " + template.getName(), ex );
            ActionMessage error = new ActionMessage(errorMessage, false);
            errors.add(error);
        } finally {
           if (tx != null && tx.isActive()) {
                tx.rollback();
            }
     }


Top
 Profile  
 
 Post subject: Re: transaction become inactive by ConstraintViolationException
PostPosted: Fri Dec 03, 2010 11:42 am 
Beginner
Beginner

Joined: Fri Nov 26, 2010 8:25 am
Posts: 21
Hi,

The rollback code should be in the exception handler, you currently have it in a finally block, so the transaction will always be rolled back whether it succeeded or not (im sure you dont want this??). If the operation succeeds and tx.commit() was called, then the transaction will be closed. Because you have the isActive() in the finally block will always be attempted and it will fail if no exception was thrown.

Try fixing that and see if you still have problems,

Kate.


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.