Questions tagged [orphan-removal]

7 questions
231
votes
8 answers

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see it is needed when I use my JPA provider's DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However,…
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103
136
votes
5 answers

What is the difference between CascadeType.REMOVE and orphanRemoval in JPA?

What's the difference between @OneToMany(cascade=REMOVE, mappedBy="customer") public List getOrders() { ... } and @OneToMany(mappedBy="customer", orphanRemoval="true") public List getOrders() { ... } This example is from Java EE…
rand0m86
  • 3,172
  • 4
  • 26
  • 29
0
votes
0 answers

Does JPA delete items from collection even without Orphan removal= true

I have the below JPA entities defined with bidirectional one-to-many mapping. I observed that delete SQL statement is fired when a comment is removed from a list on post(post.removeComment(...)) even without setting orphan removal = true or making…
swathi manda
  • 101
  • 1
  • 7
0
votes
0 answers

Does direction of join condition matter in left joins?

There are two postgres tables with roughly the following structures: products +----+-----------+ | id | rawDataId | +----+-----------+ | 1 | a | +----+-----------+ | 2 | null | +----+-----------+ | 3 | b …
GothamCityRises
  • 2,072
  • 2
  • 27
  • 43
0
votes
1 answer

Hibernate: remove and add the same entity with orphanRemoval, the entity is removed

I have a strange behavior with Hibernate. My environment is Quarkus with Panache but I think it's not really related to the issue. I'm using a simple tree entity with an id, parent and children. My moveInto method just moved a child into another…
0
votes
1 answer

moving an entity into another owned OneToMany Collection

In my application, there is a Person entity that has numerous roles of type PersonRole. @Entity public class Person { @OneToMany(mappedBy = "person", cascade=CascadeType.ALL, orphanRemoval=true, …
EasterBunnyBugSmasher
  • 1,507
  • 2
  • 15
  • 34
0
votes
1 answer

Unable to remove childs in OneToMany Mapping and add new childs [Hibernate]

I know this question has been asked many times but none of the solution is working for me. So I have a Parent class : class User{ @Id @NotNull @Column(name = "`UserId`", nullable = false) private Long userId; @OneToMany(cascade = CascadeType.ALL,…
DALJIT SINGH
  • 111
  • 1
  • 11