users@glassfish.java.net

Data lost after rollback

From: <forums_at_java.net>
Date: Fri, 8 Jul 2011 13:49:46 -0500 (CDT)

Hi, I will describe a problem the I'm having after Rollbac exception is
raised.

I have 3 tables that I'll describe with the following classes ( see end of
note )

Clients ponit to one Dialplans each and Dialplans pont to many Destinations.

When I try to remove a Dialplan, if some Client is "pointing" to it, I get a
constrain Exception and a Rollback.

After the Rollback, the Dialplan is still there  but the Destination List he
used to have ( destination it points to ), is gone !!! 

BUT ( a big BUT ) if I get a merged Dialplan entity, I can see the
Destination list just as it was but I dont see the data on the table itself
using a DB viewer (NetBeans).

After the application is closed and reopened , the data is gone. 

Looks like if the data is there but at some cache managed by the
EntityManager. It is suppose to flush all to the DB

when a Rollback is raised. I'm not using injection insted I'm getting a
EntityManager from some Factory and using it with

transactions begin, commit and all that.

What am I missing here ?

Thanks.

Albert Bonomo

@Entity

public class *Client* implements Serializable {

     // other collumns

    @ManyToOne

    private *Dialplan* dialplan;

    // getters Setters

}

@Entity

public class *Dialplan* implements Serializable {

     // other collumns

    @OneToMany

    private List<*Destination*> destinationList;

    // Getters Setters

}

@Entity

public class *Destination* implements Serializable {

    @Id

    private String pref;

    // getters Setters

}

Here is the remove mehod from the DAO

    public void *remove*(Dialplan dialplan) {

        EntityManager em = AppStart.getEntityManager();

        EntityTransaction tx = em.getTransaction();

 

        tx.begin();

        em.remove(em.merge(dialplan));

        

        try {

            tx.commit();

            

        } catch ( RollbackException e ) {

            System.out.println("Not an orphan record - " +
dialplan.toString());

        }

        em.close();

    }

 

 


--
[Message sent by forum member 'apeto']
View Post: http://forums.java.net/node/820361