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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -