-->
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: PersistentObjectException: detached entity passed to persist
PostPosted: Tue Dec 30, 2014 9:48 am 
Newbie

Joined: Mon Oct 19, 2009 4:33 pm
Posts: 8
Code:
@Override
    public void persist(ActaDiferencia entity) {
        try {
            for (ActaDiferenciaValor av : entity.getValores()) {
                getEntityManager().persist(av.getValor());
                av.setEntidadId(av.getValor().getId());
            }
            getEntityManager().persist(entity);
            getEntityManager().getTransaction().commit();
        } catch (Exception ex) {
            getEntityManager().getTransaction().rollback();
            throw ex;
        } finally {
            closeSession();
        }
    }


When some Exception is throw, I have a problem with this line: getEntityManager().persist(av.getValor());
av.getValor() has an instance of Valorizable, the ID attribute of Valorizable are setted (Integer serial on a PostgreSQL DB) and the rollingback is not clearing the ID, so, if I try to persist again the object the POException "detached entity passed to persist" shows up.
How can I solve this?, I tried to set to NULL manually on a loop every Valorizable.id but the POE keep throwing


Top
 Profile  
 
 Post subject: Re: PersistentObjectException: detached entity passed to persist
PostPosted: Mon Jan 05, 2015 12:10 pm 
Newbie

Joined: Wed Dec 24, 2014 12:20 pm
Posts: 2
for persist you should be sure, that
Code:
av.getValor().getId()=0 or NULL
.
In case what you use on your entity.
If you whant use persist make
Code:
av.getValor().setId(0 or NULL)

and than persist


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.