Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » em.merge() creates 2 insert statements
em.merge() creates 2 insert statements [message #1036617] Mon, 08 April 2013 16:04 Go to next message
Saravanan Subiramaniam is currently offline Saravanan SubiramaniamFriend
Messages: 10
Registered: April 2013
Junior Member
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 08:34]

Report message to a moderator

Re: em.merge() creates 2 insert statements [message #1037074 is a reply to message #1036617] Tue, 09 April 2013 06:32 Go to previous messageGo to next message
Saravanan Subiramaniam is currently offline Saravanan SubiramaniamFriend
Messages: 10
Registered: April 2013
Junior Member
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 15:10 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Do not call flush from inside an event (that could be trigger by a flush...).

James : Wiki : Book : Blog : Twitter
Previous Topic:Sorting of hierarchical entities in EclipseLink
Next Topic:Beginner's Problem / strange behavior
Goto Forum:
  


Current Time: Mon Nov 24 14:08:21 GMT 2014

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

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