The meaning of
It seems in your case to be a bad idea, as removing an
BTW: you may want to add a
Read full article from one to many - JPA @ManyToOne with CascadeType.ALL - Stack Overflow
CascadeType.ALL is that the persistence will propagate (cascade) all EntityManager operations (PERSIST, REMOVE, REFRESH, MERGE, DETACH) to the relating entities.It seems in your case to be a bad idea, as removing an
Address would lead to removing the related User. As a user can have multiple addresses, the other addresses would become orphans. However the inverse case (annotating the User) would make sense - if an address belongs to a single user only, it is safe to propagate the removal of all addresses belonging to a user if this user is deleted. BTW: you may want to add a
mappedBy="addressOwner" attribute to your User to signal to the persistence provider that the join column should be in the ADDRESS table.
See the docs of OpenJPA for example:
http://openjpa.apache.org/builds/latest/docs/docbook/manual/jpa_overview_meta_field.html#jpa_overview_meta_cascade
http://openjpa.apache.org/builds/latest/docs/docbook/manual/jpa_overview_meta_field.html#jpa_overview_meta_cascade
CascadeType.ALL means it will do all actions:
Quote:
CascadeType.PERSIST: When persisting an entity, also persist the entities held in this field. We suggest liberal application of this cascade rule, because if the EntityManager finds a field that references a new entity during flush, and the field does not use CascadeType.PERSIST, it is an error.CascadeType.REMOVE: When deleting an entity, also delete the entities held in this field.CascadeType.REFRESH: When refreshing an entity, also refresh the entities held in this field.CascadeType.MERGE: When merging entity state, also merge the entities held in this field.
Read full article from one to many - JPA @ManyToOne with CascadeType.ALL - Stack Overflow
No comments:
Post a Comment