Can someone take a look at JBoss debug tail while you call remove() on an entity and see what sql gets executed.
If anyone knows a way to remove an entity without first loading all it's fields. Please let me know.
I have now tried this in a configuration with an on-load strategy and an empty eager-load group.
This tells JBoss to load nothing other than the primary key the first time a method on the entity is called in a transaction. But it seems as though remove() has it's own rules and loads all the fields irrespective of load-groups.
Even some confirmation of this would be most appreciated.
If u have relation fields, then i guess all those records would be loaded as the relationship has to be removed when u delete the associated entry.
Other than that, all i can see is a sql that says
Delete from where <primary keys>
Whats the SQL that shows up when you turn the log level in the CMP classes to Debug?
Thanks for this - it gives me some hope to see when you call remove() you get no fields loaded.
I am now wondering if this has something to do with the fact that as well as my empty eager-load group, I have a lazy-load group and maybe this group is getting loaded on remove. But I'm sure I read in JBoss docs that a lazy-load group is loaded the first time a getter for an unloaded member of that group is called - which should exclude a call to remove(). I'll try commenting out the lazy-load group and see what happens.
I get SQL something like this on the debug tail:
select form table column, column, ... (all the fields) where pk=?
select column, ... (all the fields) from related where related.foreignKey = pk
this for all the relationships including ones that have no cascade-delete.
But here's a thing - At first I also thought it'd be necessary to load the relationships when removing an entity but when I think about it I wonder about that.
If I remove the one side of a one to many relationship then to cascade-delete the many side all that would required is to execute:
delete from related where related.fk = pk
If I'm removing the one side of a one to one then depending on wether its a 2 way relationship or not I can either execute the same query as above or:
delete from related where related.pk = relatedKey
So why do the relationships have to get loaded?