openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject Merge updating the wrong table
Date Sat, 18 Jul 2009 19:14:05 GMT
I have a parent entity and a child entity.  It uses a join table to hold the
relationship. When I do a get on the parent it retrieves the children
correctly but when I call merge on the parent after adding some children, it
tries to persist the children in the child table not into the join table. A
is a basic outline of my code is below.  I don't understand why the get is
working but the mere is working this way. Am I missing something obvious?

 

Parent:

 

@Entity

 

public class Role extends CoreObject{

      @OneToMany(cascade={CascadeType.ALL})

      private List <Permission> permissions;

 

      /**

       * @param permissions the permissions to set

       */

      public void setPermissions(List <Permission> permissions) {

            this.permissions = permissions;

      }

 

      /**

       * @return the permissions

       */

      public List <Permission> getPermissions() {

            return permissions;

      }

}

 

Child:

 

@Entity

 

public class Permission extends CoreObject{

 

}

 

 

I call merge like so :

 

public void merge(CoreObject co){

            EntityManagerFactory emf =
Persistence.createEntityManagerFactory(ConfigUtils.getParameter(Constants.Pa
ram_PersistenceUnit));             

            threadLocal = new ThreadLocal<EntityManager>();

            em = threadLocal.get();

            em = emf.createEntityManager();

            threadLocal.set(em);

            em.getTransaction().begin();

em.merge(co);

            em.getTransaction().commit();

em.close();

 

      }

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message