Hi Chris,Cascade ALL should not, and OpenJPA does not, include remove orphans. Simply removing an Entity from a relationship should not normally cause a life cycle change in the Entity.
There should be, and is in OpenJPA, a separate annotation for this kind of relationship. IIRC, remove orphans is being added in the JPA 2.0 spec.
Regards, Craig On Aug 3, 2009, at 11:08 AM, C N Davies wrote:
I'll 90% sure this worked ok when I was using Hibernate but doesn't seem to work on OpenJPA. I have an entity which has a collection contained in it, each of the items of this collection are entities so the collection memberis annotated as cascade ALL. If I programmatically remove one of theentities from the collection then persist the main entity, the object that was references in the list is not deleted from the DB. Is this the expectedbehaviour? Here is a sample of what I mean:Here is the main entity which as you see has a collection of Assets in it.Public class AssetRegister{ @OneToMany(cascade={CascadeType.ALL}) private List<Asset> assets; } In my code I might do like this: AssetRegister ar = <find asset register code> List<Asset> assets = ar.getAssets(); Assets.delete(<some asset>); Assets.setAssets(assets);The add and the delete to/from the collection works fine and the join in theasset register table is removed however the asset entity itself is notremoved from the asset table and since it is a OneToMany relationship theasset is now orphaned.I know I can programmatically delete the asset entity but I want to know ifthis the expected behaviour? Thanks for any advice Chris
Craig L Russell Architect, Sun Java Enterprise System http://db.apache.org/jdo 408 276-5638 mailto:[email protected] P.S. A good JDO? O, Gasp!
smime.p7s
Description: S/MIME cryptographic signature
