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 member
is annotated as cascade ALL. If I programmatically remove one of the
entities 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 expected
behaviour?
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 the
asset register table is removed however the asset entity itself is not
removed from the asset table and since it is a OneToMany relationship the
asset is now orphaned.
I know I can programmatically delete the asset entity but I want to know if
this the expected behaviour?
Thanks for any advice
Chris