Saturday, 15 May 2010

java - OneToMany: hibernate tries to nullify external reference instead of deleting whole child -


postprop = "text">

I have a unit with a list of "BigList" elements:

  @OneToMany ( Bring = FetchType.LAZY, orphanRemoval = true) @Cascade ({CascadeType.ALL}) @JoinColumn (name = "ID_LIST", referenced ColumnName = "id", updatable = true, insertable = true) @OrderBy (value = "position ASC ") list & lt; BigListElem & gt; Elements;  

BigListElem is in this context while:

  @ManyToOne (optional = false) @NotFound (action = NotFoundAction.EXCEPTION) @JoinColumn (name = " Id_list ", tapable = false, updateable = true, insertable = true) personalized BigList list;  

Now, if I delete a single element from this list and call the merge () method (thus updates) then I get the following exception:

  Impossible update ("DBNAME". "BIG_LIST_ELEM". "ID_LIST") NULL  

Instead of removing children in other words, try to empty this external reference The exception is generated, because the "unnecessary" is set to false because the external reference can not be tapped correctly. The problem is that I'm not saying zero to set this context but to remove the whole element!

Why is that?

After

Usually hibernate because if I remember correctly it is removed in such a way that on children elements The lack of FK, is being wasted:

  1. Children unit set FK to zero
  2. So if you do not have a null-constrained child unit at the database level

, you will manually delete the unit manually from DB.


No comments:

Post a Comment