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 05:06 Go to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
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?

Tom
Re: efficient cascade delete [message #527040 is a reply to message #526210] Tue, 13 April 2010 15:32 Go to previous message
James Sutherland is currently offline James Sutherland
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: Wed Jul 23 12:18:55 EDT 2014

Powered by FUDForum. Page generated in 0.02356 seconds