mysql - JPA one-to-many delete and set foregn key to null -


i use spring data, jpa, hibernate , mysql. have 1 many relation between event , category. 1 event can have 1 category , 1 category can assigned many events. problem appears when try remove category, if event hold foreign key of category error. set foreign key in event table null when category deleted. @ moment update events setting foreign key explicitly in code updating null before deletion of category. there way of doing in use of annotations?

this category:

    @entity     @table(name = "category")     public class category implements serializable{     @onetomany(mappedby="category", targetentity=event.class, fetch=fetchtype.lazy, cascade= {cascadetype.detach,  cascadetype.merge,  cascadetype.persist, cascadetype.refresh})      public set<event> getevents_category() {     return events_category;     }     } 

and event class:

@entity    @table(name = "event")    public class event implements serializable{      @manytoone(cascade={cascadetype.detach, cascadetype.merge, cascadetype.persist, cascadetype.refresh})     @joincolumn(name="events_dancestyle")     public dancestyle getdancestyle() {     return dancestyle;     }     } 

i've seen topic discussed many times haven't seen solution that.

unfortunately not possible using jpa/hibernate annotations. see these related questions:

have jpa/hibernate replicate "on delete set null" functionality

on delete set null in hibernate in @onetomany


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -