Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » efficient cascade delete
efficient cascade delete [message #526210] Fri, 09 April 2010 09:06 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 812
Registered: July 2009
Senior Member
We have a double 1-N setup with cascade delete: A -> B -> C.

If we delete A then all referred B's and by those referred C's are deleted. Eclipselink does this by first selecting all the referred B's and then selecting all the referred C's and then deleting them. This naturally is very inefficient from a database perspective, but I understand that this is required to make sure the cache is correct.

The only way to do this more efficiently is to use native sql and clear both level caches?

Re: efficient cascade delete [message #527040 is a reply to message #526210] Tue, 13 April 2010 19:32 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If you use @PrivateOwned instead of cascade EclipseLink should optimize the deletion to avoid reading in the related objects. It will still read in B to delete the C's, but should not need to read C, unless C is using optimistic locking or has its own dependencies.

You could set the cascade on the constraint in the database instead of in JPA. This would mean that A would be removed from the cache, but not B or C. This might be ok, B and C should eventually garbage collect from the cache. The only way you could get B or C would be by a primary key query, if your app would never do this, then may be fine just leaving the cache as is. Otherwise you could invalidate the C and B caches.

James : Wiki : Book : Blog : Twitter
Previous Topic:Class loading problem on new() in JPQL
Next Topic:Open session in view
Goto Forum:

Current Time: Thu Jun 21 20:20:52 GMT 2018

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

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

Back to the top