-->
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 STATUS_MARKED_ROLLBACK after PersistenceExceptio
PostPosted: Mon Jul 30, 2012 1:08 pm 
Newbie

Joined: Mon May 31, 2010 7:29 am
Posts: 5
I have a situation witch I need my transaction to keep active after an handable persistence error occurs. But HibernateEntityManager sets my transaction as STATUS_MARKED_ROLLBACK before i can threat it. Here is my flow:

Code:


@PersistenceContext(unitName="MY_PU")
EntityManager entityManager;

@Inject
UserTransaction ut;

public void action() throws NotSupportedException, SystemException{
        ut.begin();
        Person p = new Person();
         
        p.setIdPerson(1L);
        //Will force a errors because this field has only 5 characters on database
        p.setName("abcdef");
         
        try{
                entityManager.persist(p);
                entityManager.flush();
        }catch (Exception e) {
                System.out.println("Here a persistence exception, but i need to continue my transaction");
                e.printStackTrace();
        }
         
        p.setName("abc");
         
        try{
                entityManager.persist(p);
                //This flush will throw a exception accusing no transaction active!
                entityManager.flush();
                ut.commit();
        }catch (Exception e) {
                e.printStackTrace();
                System.out.println("Another error, because my transaction is no more active");
                System.out.println("Status:" + ut.getStatus());
        }
}



This occurs because at org.hibernate.ejb.AbstractEntityManagerImpl there is a error treatment that sets my transaction as Rollback Only when any exception throwned.

Is there some way I can intercept this? Making hibernate do not mark my transaction to rollback?

I am running my app as an WAR with CDI on jboss-as-7.1.1.Final (default standalone configuration).


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.