In JBoss 3.0.x, <cascade-delete> deletes child entities one at a time. This makes sense when an in-memory cache needs to be maintained -- you need to know which entities to remove from the cache.

But when there is no cache (e.g., commit option C), there are several more efficient approaches:

a. delete all children in a single step

DELETE FROM Child WHERE ParentId = <parent-key>
DELETE FROM Parent WHERE Id = <parent-key>

(Others have suggested this one as well)

b. leverage the database's own ON DELETE CASCADE

CREATE TABLE Child
...
ParentId FOREIGN KEY REFERENCES Parent(Id) ON DELETE CASCADE

DELETE FROM Parent WHERE Id = <parent-key>

One nice property of (b), for the databases which support it and for applications without caching, is that the CMP code needs to do very little! :-) ON DELETE CASCADE is supported by at least Oracle and SqlServer.

BTW, I would not expect the <create-table> element to create this FOREIGN KEY (that is a bit much, given the slightly different SQL syntaxes involved), but it would be ideal if there were a configuration option to tell CMP that such a DB constraint existed.

I have searched jboss-user, jboss-development, the forums, and the task list, and I am not sure whether this is a planned feature or not. It sounds like there are tons of CMP improvements in the works for 4.0 -- is a configuration option to use the database's ON DELETE CASCADE one of them?

Thanks,
-- Randy
_________________________________________________________________
Randy Shoup
Tumbleweed Communications Corporation





-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to