Michał Sobkiewicz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDc1YTM4NDMy...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiMDc1YT...
) HHH-15734 (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiMDc1YT...
) orphanRemoval delete entity if moved to freshly added parent (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiMDc1YT...
)
Issue Type: Bug Affects Versions: 6.1.5 Assignee: Unassigned Components:
hibernate-entitymanager Created: 18/Nov/2022 08:47 AM Priority: Major Reporter: Michał
Sobkiewicz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Given the following tree-like structure…
@Entity
class Node {
@Id
String id;
@ManyToOne
Node parent;
@OneToMany(mappedBy = "parent" , cascade = CascadeType.ALL, orphanRemoval =
true )
Set<Node> children;
}
… I’d like to be able freely move children between parents. I can easily do that when all
entities involved in such transaction (2 parents and 1 child) are already persistent. It’s
impossible however to insert new (transient) node “between” two existing nodes.
I’m unable to make
a
└── b
become
a
└── x
└── b
if x is transient, as Hibernate deletes b.
Adding x in between a and b involves 2 steps:
* removing b from a.children
* adding b to x.children
I suppose that step 1. makes Hibernate to mark b for deletion. Step 2. should somehow undo
this - and it does, but only when x is already managed (and so is x.children collection).
It’s worth noting that x becomes managed in the very same transaction because of
CASCADE.ALL on a.children. I even tried to explicitly call persist but it doesn't
change anything - b is being deleted anyway.
This looks like a bug.
I've created SSCCE:
https://github.com/perceptron8/orphan-removal
cd orphan-removal
mvn test
Please let me know if I can help somehow.
(
https://hibernate.atlassian.net/browse/HHH-15734#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15734#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:9b34d7c )