[SOLVED] integrity constraint violation after mergin list of unmanaged entities [message #957722] |
Thu, 25 October 2012 12:47 |
Andre Albert Messages: 25 Registered: July 2009 |
Junior Member |
|
|
Hello,
I have this weird situation that after merging a list of unmanaged and managed entities, I get PK constraint errors while committing changes to DB.
The entities are transmitted between Client/Server and are unmanaged before each step in the procedure.
It happens when first persisting an entity containing a list of entities and afterwards removing one entity from this list and finally adding a new Entity to this list.
I am using eclipselink 4.2.0
I have a stripped down example:
@Entity
public class Parent implements Serializable{
@Id @GeneratedValue
public Long id;
@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
public List<Children> childs = new ArrayList<Children>();
}
and
@Entity
public class Children implements Serializable {
@Id @GeneratedValue
public Long id;
}
The following Main Method for example crashes all the time (stacktrace.log attached).
public static void main(final String[] args) {
EntityManager em = createEntityManager();
Parent p = new Parent();
Children c1 = new Children();
Children c2 = new Children();
p.childs.add(c1);
p.childs.add(c2);
EntityTransaction transaction = em.getTransaction();
transaction.begin();
em.persist(p);
transaction.commit();
em.close();
// simulate a new Client Request which always get a new EntityManager
em = createEntityManager();
Parent pNeu = new Parent();
Children c1Neu = new Children();
pNeu.id = p.id;
c1Neu.id= c1.id;
pNeu.childs.add(c1Neu);
transaction = em.getTransaction();
transaction.begin();
em.merge(p);
transaction.commit();
em.close();
// simulate a new Client Request which always get a new EntityManager
em = createEntityManager();
pNeu = new Parent();
pNeu.id = p.id;
c1Neu = new Children();
c1Neu.id= c1.id;
Children c2Neu = new Children();
p.childs.add(c1Neu);
p.childs.add(c2Neu);
transaction = em.getTransaction();
transaction.begin();
em.merge(p);
transaction.commit();
em.close();
}
Can someone please tell me what I am doing wrong?
Thanks in advance
Regards
---
Solution:
It turns out that the (real) entities I am using failing the hash/equals contract
[Updated on: Thu, 25 October 2012 14:24] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04303 seconds