Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unwanted aggregated child cascade delete(EclipseLink is trying to delete aggregated child)
Unwanted aggregated child cascade delete [message #652830] Mon, 07 February 2011 09:18 Go to next message
Jules is currently offline JulesFriend
Messages: 8
Registered: August 2010
Junior Member
I wonder if anyone can advise on what seems like incorrect behaviour by EclipseLink? Here is my scenario:

Two related entities PARCEL and COLOR. The colors are fixed configuration data. A parcel defines the relationship:

@ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER)
@JoinColumn(name = "COLOR_ID", nullable = false)
private Color parcelColor;

There is no annotation in Color pointing to Parcel because there will never be any necessity to navigate from Color to Parcel. And of course there may be many other types of entity that also have a color.

When I try to remove a Parcel object EclipseLink is also trying to delete the respective Color object and this mustn't happen (because other Parcel objects point to the same Color object there was a foreign key constraint violation exception which highlighted the problem).

The lifecycle was:
Web client (out of transactional context) finds Parcel object.
Web client sends parcel object to server tier (transactional context)
Server tier does EntityManager.merge()
Server tier does EntityManager.remove()

No attempt currently made at setting Parcel child objects to null

By the book I thought the annotation is correct - can anyone advise?
Re: Unwanted aggregated child cascade delete [message #652907 is a reply to message #652830] Mon, 07 February 2011 14:47 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

The annotation looks fine and will not cause Color to be deleted by itself. What would is if you had cascade remove or were using the OrphanRemoval (or its EclipseLink twin, privateOwnership) annotations.

There is not enough information given to help diagnose what could be going wrong. I would suggest you turn on EclipseLink logging ( <property name="eclipselink.logging.level" value="FINEST"/> ) and possibly put in entityManager flush calls to see if this could be the result of code using this same transaction context. Do any of the other relations to color use private ownership or orphanremoval?

Best Regards,
Chris
Re: Unwanted aggregated child cascade delete [message #652989 is a reply to message #652907] Mon, 07 February 2011 20:17 Go to previous message
Jules is currently offline JulesFriend
Messages: 8
Registered: August 2010
Junior Member
Hi Chris thanks for the reply.

Although you say the annotation looks ok and it shouldn't cause a delete, EclipseLink is trying to do just that.

Watching the emitted SQL the delete statements tackle child objects first as expected, then the Parcel object itself then an attempt is made to delete the parcelColor object.

This is such a fundamental issue but I can't see whats wrong.

I'll post the complete code tomorrow, a working illustration and details of the software versions.
Previous Topic:Exception [EclipseLink-6044] Primary keys must not contain null.
Next Topic:@NamedStoredProcedureQuery & Out Parameter:
Goto Forum:
  


Current Time: Tue Apr 16 17:59:39 GMT 2024

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

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

Back to the top