Skip to content
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 @@ -690,7 +690,7 @@ protected void firePostRemove(PersistentCollection<?> collection, Object id, Str

// collections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Hibernate Reactive overrides this
// Hibernate Reactive calls this
protected void forEachOwnedCollection(
Object entity, Object key,
EntityPersister persister, BiConsumer<CollectionPersister, PersistentCollection<?>> action) {
Expand All @@ -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 @@ -726,12 +726,12 @@ protected PersistentCollection<?> instantiateEmpty(Object key, CollectionPersist
return descriptor.getCollectionSemantics().instantiateWrapper(key, descriptor, this);
}

//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