Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » em.merge() creates 2 insert statements
em.merge() creates 2 insert statements [message #1036617] Mon, 08 April 2013 12:04 Go to next message
Eclipse UserFriend
Hi,
I've PrePersist lifecycle method in my entity and within that method, I've a call to em.flush().

When this entity is merged using em.merge(), there are 2 insert statments created. Why does em see 2 different object change sets, could anyone explain this behavios?

Example:
public class MyEntity{
@OneToMany(cascade = CascadeType.ALL, targetEntity = Detail.class, mappedBy = "parent")
private List<Detail> childList;

@PrePersist
public void prePersist(){
doSomething();
em.flush();
}
}

MyEntity myEntity = new MyEntity();
myEntity.setSomeField();
myEntity.setChildList(childList);
em.merge(myEntity);


Thanks,
Saravanan,
Oracle Netherlands.

[Updated on: Tue, 09 April 2013 04:34] by Moderator

Re: em.merge() creates 2 insert statements [message #1037074 is a reply to message #1036617] Tue, 09 April 2013 02:32 Go to previous messageGo to next message
Eclipse UserFriend
Just observed that PrePersist lifecycle method is invoked again and again afer em.flush(). Since we've UK on the table, the second insert statment failed. When the UK is disabled, the PrePersist method is invoked around 4-5 times and then the cycle ends.
Re: em.merge() creates 2 insert statements [message #1037445 is a reply to message #1037074] Tue, 09 April 2013 11:10 Go to previous message
Eclipse UserFriend
Do not call flush from inside an event (that could be trigger by a flush...).
Previous Topic:Sorting of hierarchical entities in EclipseLink
Next Topic:Beginner's Problem / strange behavior
Goto Forum:
  


Current Time: Thu Jul 24 10:41:45 EDT 2025

Powered by FUDForum. Page generated in 0.05584 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top