Skip to content

Commit d82913d

Browse files
committed
HHH-18544 multiload() and findAll() should return existing proxies
1 parent 47270d4 commit d82913d

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdEntityLoaderArrayParam.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ protected <K> List<E> performOrderedMultiLoad(K[] ids, MultiIdLoadOptions loadOp
218218
// the entity is locally deleted, and the options ask that we not return such entities...
219219
entity = null;
220220
}
221+
else {
222+
entity = persistenceContext.proxyFor( entity );
223+
}
221224
}
222225
result.set( resultIndex, entity );
223226
}

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdEntityLoaderStandard.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ protected List<T> performOrderedMultiLoad(
188188
// the entity is locally deleted, and the options ask that we not return such entities...
189189
entity = null;
190190
}
191+
else {
192+
entity = persistenceContext.proxyFor( entity );
193+
}
191194
}
192195
result.set( position, entity );
193196
}

hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/FindAllTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static org.hibernate.ReadOnlyMode.READ_ONLY;
1313
import static org.junit.jupiter.api.Assertions.assertEquals;
1414
import static org.junit.jupiter.api.Assertions.assertNull;
15+
import static org.junit.jupiter.api.Assertions.assertSame;
1516
import static org.junit.jupiter.api.Assertions.assertTrue;
1617

1718
@SessionFactory
@@ -35,6 +36,11 @@ public class FindAllTest {
3536
assertTrue(s.isReadOnly(all.get(0)));
3637
assertTrue(s.isReadOnly(all.get(1)));
3738
});
39+
scope.inTransaction(s-> {
40+
Record record = s.getReference(Record.class, 456L);
41+
List<Record> all = s.findAll(Record.class, List.of(456L, 123L));
42+
assertSame(record, all.get(0));
43+
});
3844
}
3945
@Entity
4046
static class Record {

hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiLoadTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void testBasicMultiLoadWithManagedAndChecking(SessionFactoryScope scope)
276276
);
277277
}
278278

279-
@Test @FailureExpected(jiraKey = "HHH-18544")
279+
@Test
280280
public void testBasicMultiLoadWithManagedAndNoCheckingProxied(SessionFactoryScope scope) {
281281
scope.inTransaction(
282282
session -> {
@@ -290,7 +290,7 @@ public void testBasicMultiLoadWithManagedAndNoCheckingProxied(SessionFactoryScop
290290
);
291291
}
292292

293-
@Test @FailureExpected(jiraKey = "HHH-18544")
293+
@Test
294294
public void testBasicMultiLoadWithManagedAndCheckingProxied(SessionFactoryScope scope) {
295295
scope.inTransaction(
296296
session -> {

0 commit comments

Comments
 (0)