title: Hibernate JPA cascade delete with DiscriminatorColumn
body: <p>I am using Hibernate's implementation of JPA. I have a user table with different types of users(Private | Public etc..), the user_type column specifies the types of the user. </p>
  
  <p>I have a User class which is an entity that represents user table. I added </p>
  
  <pre><code>@DiscriminatorColumn(name="user_type", discriminatorType=DiscriminatorType.STRING) 
  </code></pre>
  
  <p>on my User class and created 2 classes, PrivateUser and PublicUser each of them extending User Class with corresponding @DiscriminatorValue.</p>
  
  <p>I also have PrivateCompany and PublicCompany tables which has one to many relationship PrivateUser entity and PublicUser entity respectively using a column called company_id in user table. I also have a Cascade delete on both OneToMany Relationships.</p>
  
  <p>Now if I have a PrivateCompany with id 10 and a PublicCompany with ID 10 and user entries in user table for both PrivateCompany and PublicCompany like the following.</p>
  
  <pre><code>user_id | company_id | user_type
  100       10           private
  101       10           public
  </code></pre>
  
  <p>If I delete the PrivateCompany, I am ending up deleting user 101 along with 100 because the OneToMany relationship in on company_id and it does not consider the user_type column despite its mention as DiscriminatorColumn. I am looking for a way to give cascade delete functionality which accounts DiscriminatorColumn while deleting the children. I tried to create JoinColumns with multiple columns, but I can create the relationship with column name but not column value(which is my case). </p>
  
  <p>Please let me know if my explanation is not clear.</p>
  
  <p>Thanks in advance</p>