Skip to content

HHH-19716 Set the collection owner when wrapping a collection into a persistent one #10778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ protected void forEachOwnedCollection(
collection =
value == null
? instantiateEmpty( key, descriptor )
: wrap( descriptor, value );
: wrap( descriptor, value, entity );
}
action.accept( descriptor, collection );
}
Expand All @@ -729,9 +729,11 @@ protected PersistentCollection<?> instantiateEmpty(Object key, CollectionPersist
//TODO: is this the right way to do this?
// Hibernate Reactive calls this
@SuppressWarnings({"rawtypes", "unchecked"})
protected PersistentCollection<?> wrap(CollectionPersister descriptor, Object collection) {
protected PersistentCollection<?> wrap(CollectionPersister descriptor, Object collection, Object owner) {
final CollectionSemantics collectionSemantics = descriptor.getCollectionSemantics();
return collectionSemantics.wrap(collection, descriptor, this);
var wrapped = collectionSemantics.wrap( collection, descriptor, this );
wrapped.setOwner( owner );
return wrapped;
}

// loading ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

@DomainModel(annotatedClasses = {EntityA.class, EntityB.class})
Expand Down Expand Up @@ -64,6 +65,8 @@ class MyPreCollectionRecreateEventListener implements PreCollectionRecreateEvent

@Override
public void onPreRecreateCollection(PreCollectionRecreateEvent event) {
assertThat( event.getAffectedOwnerOrNull() ).isNotNull();
assertThat( event.getCollection().getOwner() ).isNotNull();
called++;
}

Expand All @@ -75,6 +78,8 @@ class MyPreCollectionRemoveEventListener implements PreCollectionRemoveEventList

@Override
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
assertThat( event.getAffectedOwnerOrNull() ).isNotNull();
assertThat( event.getCollection().getOwner() ).isNotNull();
called++;
}

Expand All @@ -86,6 +91,8 @@ class MyPostCollectionRecreateEventListener implements PostCollectionRecreateEve

@Override
public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
assertThat( event.getAffectedOwnerOrNull() ).isNotNull();
assertThat( event.getCollection().getOwner() ).isNotNull();
called++;
}

Expand All @@ -97,6 +104,8 @@ class MyPostCollectionRemoveEventListener implements PostCollectionRemoveEventLi

@Override
public void onPostRemoveCollection(PostCollectionRemoveEvent event) {
assertThat( event.getAffectedOwnerOrNull() ).isNotNull();
assertThat( event.getCollection().getOwner() ).isNotNull();
called++;
}

Expand Down