java - Suppress cascade delete annotation function when not needed in JPA CRUD -
i have 2 entities parent , child in bidirectional relationship this:
@entity public class parent implements serializable { @id @generatedvalue private long id; @onetomany(mappedby = "parent", cascade = cascadetype.remove) private set<child> children; } @entity public class child implements serializable { @id @generatedvalue private long id; @manytoone @joincolumn private parent parent; }
through annotation, when delete entry of parent in database, child related deleted through cascade.
however, there cases parent has no child; therefore, cascade delete not needed.
i want differentiate delete operation in terms of whether cascade needed (e.g. deletion simple delete or delete requires cascade). without making explicit call on parent check if children null, there way jpa automatically suppress cascade annotation when not needed in command 1 below?
this.parentrepository.delete(parentid);
Comments
Post a Comment