Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As said</p> <blockquote> <p>When i try deleting the UserProfile entity, the corresponding User entity still stays</p> </blockquote> <p>Maybe when you try to remove a UserProfile you get an integrity constraint violation from the database - do you use MyISAM engine in MySQL ?</p> <p>But as you does not says nothing about it. Maybe your UserProfile entity does not have a reference to a User entity. </p> <p>As said in JPA specification</p> <blockquote> <p>remove operation <strong>is cascaded to entities referenced by X</strong>, if the relationship from X to these other entities is annotated with the cascade=REMOVE or cascade=ALL annotation element value</p> </blockquote> <p>Something like</p> <pre><code>UserProfile up = entityManager.find(UserProfile.class, id); entityManager.close(); // Notice User is null outside a persistence context // So user will be not removed from the database because UserProfile does not have a reference to it up.setUser(null); entityManager.getTransaction().begin(); entityManager.remove(up); entityManager.getTransaction().commit(); </code></pre> <p>Or you have something like</p> <pre><code>entityManager.getTransaction().begin(); UserProfile up = entityManager.find(UserProfile.class, id); // throws UPDATE USER_PROFILE SET USER_ID = NULL up.setUser(null); // up.getUser() is null // So user is not removed entityManager.remove(up); entityManager.getTransaction().commit(); </code></pre> <p>In response to ChhsPly's comment:</p> <p>In Java Persistence with Hibernate book, you see the following</p> <blockquote> <p>The cascade attribute is directional: <strong>It applies to only one end of the association</strong>. </p> </blockquote> <p>I think it would be better as</p> <blockquote> <p>It applies to only one end of the association <em>per operation</em></p> </blockquote> <p>So you can put cascade attribute in both sides at the same time, even in a bidirectional relationship. So ChssPly is right.</p> <p>mappdeBy attribute <strong>sets up the bidirectional relationship</strong>. mappedBy attribute designated the Address entity as the inverse side of the relationship. This means that the Customer entity is the owning side of the relationship.</p> <p>ChssPly is right when he says <em>mappedBy has nothing to do with cascading</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload