[hibernate] hibernate在级联删除时会先将子对象的外键值置为null

    如果子对象的外键值已设为not null,级联删除时就会出问题

   要解决这个问题,有两种办法:

    1.取消掉外键的 not null

    2. set, bag 那一端设置 inverse = true

   

原文:

Very Important Note: If the <key> column of a <one-to-many> association is declared NOT NULL, Hibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true".

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.