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