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: batch commit with ConstrainViolationException
PostPosted: Fri Mar 18, 2005 12:13 pm 
Newbie

Joined: Fri Mar 18, 2005 11:47 am
Posts: 1
Hi,

I have a requirement to use JTA transacation manager, batch commit and commit the batch even if ConstraintViolationException is thrown.

Currently I am getting an exception during the commit of the batch, and the object identifier show it is the same object that is causing the unique constraint violation.

"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for HierarchyNode instance with identifier: 42884; nested exception is net.sf.hibernate.StaleObjectStateException: "

snip*

Code:
       Session session = SessionFactoryUtils.getSession(getSessionFactory(), true);
       
        try
        {
            session.save(node);
            session.flush();
        }
        catch(ConstraintViolationException e)
        {
            try
            {
                session.evict(node);
                session.cancelQuery();
                node.setID(null);
                node.setVersion(null);
            }
            catch (HibernateException e1){e1.printStackTrace();}
        }


Is it possible with hibernate to bind batches insert in one transaction, the first insert succeed, the second insert violate unique constraint and I go ahead and commit anyway, because I want first insert to go into the db. In the code snippet I try to evict, cancelQuery, setId and version to null to the object causing the problem. But still get the StaleObjectStateException on commit. How can I achieve this with hibernate?

Thank you.
Code:


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.