• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Eclipselink orphanRemoval in embedded entity not working  RSS feed

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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
Code: [Select all] [Show/ hide]
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:

Code: [Select all] [Show/ hide]
@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.

Code: [Select all] [Show/ hide]
java.lang.NullPointerException
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:696)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:438)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:863)
at OrphanRemovalTest.saveFlushAndClear(OrphanRemovalTest.java:74)
at OrphanRemovalTest.testApp(OrphanRemovalTest.java:47)


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

Please help how to solve this issue.

Regards,
Sunil
 
We don't have time for this. We've gotta save the moon! Or check this out:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!