Deleting ObjEntity with flattened attribute

"Jurgen Doll" <[email protected]> Wed, 01 May 2024 12:29:28 +0200
Newsgroups gmane.comp.java.cayenne.user
Organization iVory EMR
Message-ID <op.2m28recxy9kazd__34330.7955235773$1714895894$gmane$org@admin-pc>
Hi All

I've recently upgraded from Cayenne 3.1 to 4.2 and noticed that when  
deleting an ObjEntity with flattened attributes Cayenne now deletes the  
related DB attribute's row as well.

So if we have for example an ObjEntity "FlatPainting" with flattened  
attribute "galleryName". If we then delete a "FlatPainting" then the  
associated gallery will also be deleted, leaving all other paintings at  
that gallery without a valid Gallery link.

Furthermore if we add to our "FlatPainting" a "gallery" relationship  
attribute with delete rule Deny, the gallery is still deleted.

I would submit a bug report and PR to fix but looking at the code [1] and  
tests [2] I was surprised to find that the behavior of the first example  
appears to be intentional which is why I'm writing this email.

Unless I'm missing something I would like to submit said bug report and PR  
to revert this to either 3.1 behavior (no cascade delete) or a modified  
version of the current behavior.

I think the original intention was for something like a "PaintingFull"  
ObjEntity having all painting attributes and a flattened attribute to  
"PaintingInfo" as well, where the relationship is 1:1. In this case it  
makes sense that deleting a "PaintingFull" should also delete its  
associated PaintingInfo record.

If there's no objection I could try and add a check for this and only do  
the delete if the relationship is 1:1 and there's no relationship  
attribute with delete rule Deny. If it's too complicated I'd just revert  
the current behavior to 3.1

Thoughts please.

Thanks, regards
Jurgen

[1] RootRowOpProcessor.visitDelete
[2] DataContextFlattenedAttributesIT.testDelete