HHH-18544 multiload() and findAll() should return existing proxies

This commit is contained in:
Gavin King 2024-09-11 00:58:05 +02:00
parent 47270d4157
commit d82913d65f
4 changed files with 14 additions and 2 deletions

View File

@ -218,6 +218,9 @@ public class MultiIdEntityLoaderArrayParam<E> extends AbstractMultiIdEntityLoade
// the entity is locally deleted, and the options ask that we not return such entities...
entity = null;
}
else {
entity = persistenceContext.proxyFor( entity );
}
}
result.set( resultIndex, entity );
}

View File

@ -188,6 +188,9 @@ public class MultiIdEntityLoaderStandard<T> extends AbstractMultiIdEntityLoader<
// the entity is locally deleted, and the options ask that we not return such entities...
entity = null;
}
else {
entity = persistenceContext.proxyFor( entity );
}
}
result.set( position, entity );
}

View File

@ -12,6 +12,7 @@ import java.util.List;
import static org.hibernate.ReadOnlyMode.READ_ONLY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SessionFactory
@ -35,6 +36,11 @@ public class FindAllTest {
assertTrue(s.isReadOnly(all.get(0)));
assertTrue(s.isReadOnly(all.get(1)));
});
scope.inTransaction(s-> {
Record record = s.getReference(Record.class, 456L);
List<Record> all = s.findAll(Record.class, List.of(456L, 123L));
assertSame(record, all.get(0));
});
}
@Entity
static class Record {

View File

@ -276,7 +276,7 @@ public class MultiLoadTest {
);
}
@Test @FailureExpected(jiraKey = "HHH-18544")
@Test
public void testBasicMultiLoadWithManagedAndNoCheckingProxied(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
@ -290,7 +290,7 @@ public class MultiLoadTest {
);
}
@Test @FailureExpected(jiraKey = "HHH-18544")
@Test
public void testBasicMultiLoadWithManagedAndCheckingProxied(SessionFactoryScope scope) {
scope.inTransaction(
session -> {