Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA - orphanRemoval in embedded entity not working
JPA - orphanRemoval in embedded entity not working [message #1279753] Sat, 29 March 2014 06:56 Go to next message
Florian Jung is currently offline Florian JungFriend
Messages: 1
Registered: March 2014
Junior Member
I experienced some weird behaviour of JPA (EclipseLink and Hibernate) and I can't find it defined in the specs, so I hope someone can give me a hint.

Given the following scenario:

Entity C is assigned to table C
Entity B is an @Embeddable
- having a unidirectional @OneToOne reference to C (orphanRemoval=true)

Entity A
is assigned to table A
- having an @Embedded reference to B
- having a unidirectional @OneToOne reference to C (orphanRemoval=true)

When I create an instance of
a -------- (1 : 1) ------> c1  
  \----- (embedded) -----> b ------- (1 : 1) -------> c2

a having the 1:1 relation to c1 and having the relation to c2 via b and save it to the database, all SQL statements are created as expected. When I set both references to C (namely c1 and c2) to null and save the same entity again, I expect JPA to set the fields to null and delete the orphans afterwards.

Deletion of C takes place only for c1. c2 is not being deleted, though both fields are set to null.

The relations to C are are annotated as given below:

@OneToOne(cascade = {PERSIST, MERGE, REFRESH}, orphanRemoval = true)
@JoinColumn(name = "<field_name>")
private C c;

This behaviour can be seen with all EclipseLink version starting from 2.3.3 up to 2.5.2-M1, as well as with Hibernate 4.3.4. EclipseLink only works (but showing the weird behaviour) when the entities are enhanced by static weaving. Without static weaving there is a NullPointerException in UnitOfWorkImpl.calculateChanges.

	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(
	at OrphanRemovalTest.saveFlushAndClear(
	at OrphanRemovalTest.testApp(

Even using @PrivateOwned in conjunction with EclipseLink does not change anything.

Is there any explanation for this?
Re: JPA - orphanRemoval in embedded entity not working [message #1743249 is a reply to message #1279753] Tue, 13 September 2016 14:20 Go to previous messageGo to next message
Juan Llado is currently offline Juan LladoFriend
Messages: 3
Registered: April 2016
Junior Member
It's an old post but I'm suffering the same issue...

Does anyone know how to avoid this problem? Is it a bug? Or it's a not supported feature...

Re: JPA - orphanRemoval in embedded entity not working [message #1743798 is a reply to message #1743249] Mon, 19 September 2016 16:33 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1187
Registered: July 2009
Senior Member
There are a few inconsistencies and problems in the original post to comment. First, it states it doesn't work with some specific versions of EclipseLink. Then it states it does work with static weaving, but they get an NPE without static weaving. Do these non-working versions of EL get the NPE, or is the NPE only on the latest versions? It is difficult to surmise what might be happening when it isn't certain that weaving was setup correctly.

The original post implies that it is working in some specific situations, so what exact issue are you seeing and what exact version(s) are you using?
Previous Topic:Forcing a different operations order on persited entity
Next Topic:Turning off query Caching in Spring Data
Goto Forum:

Current Time: Sun Oct 23 03:17:37 GMT 2016

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

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