Combining delete-orphan with the where clause

The issue of sleep mode, where the behavior is ambiguous and / or dangerous. I have a one-to-many relationship that has a cascade-delete-orphan condition. And where is the condition for restricting items in the collection. Display here -

<hibernate-mapping>
 <class name="User" table="user" > 

  <!-- properties and id ... -->

   <set table="email" inverse="true" cascade="all,delete-orphan" where="deleted!=true">
      <key column="user_id">
      <one-to-many class="Email"/>
   </set>

 </class>
</hibernate-mapping>

Now suppose I have a User object that is associated with one or more email objects, at least one of which is true for the remote property. Which of the following two happens when I call session.delete () in a User object?

  • The user and all email objects, including deleted = true, are deleted.
  • User and email objects deleted! = Null are deleted.

, 1) where, . 2), , child (email), . ? , Hibernate ?

+5
1

, , , ( ) , where ( , FK ). "" - , "", .

, . delete ( Email ).

, , , User, Email. - :

<hibernate-mapping>
  <class name="User" table="user" where="deleted<>'1'"> 

    <!-- properties and id ... -->

    <set table="email" inverse="true" cascade="all,delete-orphan" where="deleted<>'1'">
      <key column="user_id">
      <one-to-many class="Email"/>
    </set>
    <sql-delete>UPDATE user SET deleted = '1' WHERE id = ?</sql-delete>
  </class>

  <class name="Email" table="email" where="deleted<>'1'"> 

    <!-- properties and id ... -->

    <sql-delete>UPDATE email SET deleted = '1' WHERE id = ?</sql-delete>
  </class>
</hibernate-mapping>

:

  • sql-delete, ( ).
  • where , .

Hibernate. .

+4

All Articles