Michał Sobkiewicz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiY2RhOTFhOTA2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiY2RhOT...
) HHH-15734 (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiY2RhOT...
) orphanRemoval: Hibernate deletes entity if moved to freshly added parent (
https://hibernate.atlassian.net/browse/HHH-15734?atlOrigin=eyJpIjoiY2RhOT...
)
Change By: Michał Sobkiewicz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Given the following tree-like structure…
{code:java}@Entity
class Node {
@Id
String id;
@ManyToOne
Node parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval =
true)
Set<Node> children;
}{code}
… 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
{noformat}a
└── b{noformat}
become
{noformat}a
└── x
└── b{noformat}
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(x)}} but it doesn't change anything - {{b}} is being deleted anyway.
This looks like a bug.
----
I've created SSCCE:
{noformat} git clone
https://github.com/perceptron8/orphan-removal
cd orphan-removal
mvn test{noformat}
----
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:4037f92 )