Skip to content

Commit 62e1b04

Browse files
committed
HHH-17948 make getAll(), findAll() accept List instead of varargs
1 parent 7e36768 commit 62e1b04

File tree

8 files changed

+17
-22
lines changed

8 files changed

+17
-22
lines changed

hibernate-core/src/main/java/org/hibernate/Session.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,16 +705,13 @@ public interface Session extends SharedSessionContract, EntityManager {
705705
* {@link MultiIdentifierLoadAccess}.
706706
*
707707
* @param entityType the entity type
708-
* @param ids the identifiers
709-
*
708+
* @param ids the identifiers
710709
* @return an ordered list of persistent instances, with null elements representing missing
711-
* entities
712-
*
713-
* @since 7.0
714-
*
710+
* entities
715711
* @see #byMultipleIds(Class)
712+
* @since 7.0
716713
*/
717-
<E> List<E> findAll(Class<E> entityType, Object... ids);
714+
<E> List<E> findAll(Class<E> entityType, List<Object> ids);
718715

719716
/**
720717
* Return the persistent instance of the given entity class with the given identifier,
@@ -925,7 +922,7 @@ public interface Session extends SharedSessionContract, EntityManager {
925922
*
926923
* @throws HibernateException If the given class does not resolve as a mapped entity
927924
*
928-
* @see #findAll(Class, Object...)
925+
* @see #findAll(Class, List)
929926
*/
930927
<T> MultiIdentifierLoadAccess<T> byMultipleIds(Class<T> entityClass);
931928

hibernate-core/src/main/java/org/hibernate/StatelessSession.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,12 @@ public interface StatelessSession extends SharedSessionContract {
260260
* instance matching a given identifier.
261261
*
262262
* @param entityClass The class of the entity to retrieve
263-
* @param ids The ids of the entities to retrieve
264-
*
263+
* @param ids The ids of the entities to retrieve
265264
* @return an ordered list of detached entity instances, with
266-
* null elements representing missing entities
267-
*
265+
* null elements representing missing entities
268266
* @since 7.0
269267
*/
270-
<T> List<T> getAll(Class<T> entityClass, Object... ids);
268+
<T> List<T> getAll(Class<T> entityClass, List<Object> ids);
271269

272270
/**
273271
* Refresh the entity instance state from the database.

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ public void detach(Object entity) {
954954
}
955955

956956
@Override
957-
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
957+
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
958958
return delegate.findAll( entityType, ids );
959959
}
960960

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void clear() {
264264
}
265265

266266
@Override
267-
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
267+
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
268268
return this.lazySession.get().findAll( entityType, ids );
269269
}
270270

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ public Object load(String entityName, Object id) throws HibernateException {
948948
}
949949

950950
@Override
951-
public <E> List<E> findAll(Class<E> entityType, Object... ids) {
951+
public <E> List<E> findAll(Class<E> entityType, List<Object> ids) {
952952
return this.byMultipleIds( entityType ).multiLoad( ids );
953953
}
954954

hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public <T> T get(
513513
}
514514

515515
@Override
516-
public <T> List<T> getAll(Class<T> entityClass, Object... ids) {
516+
public <T> List<T> getAll(Class<T> entityClass, List<Object> ids) {
517517
for (Object id : ids) {
518518
if ( id == null ) {
519519
throw new IllegalArgumentException("Null id");
@@ -522,13 +522,13 @@ public <T> List<T> getAll(Class<T> entityClass, Object... ids) {
522522
final EntityPersister persister = getEntityPersister( entityClass.getName() );
523523
final JpaCriteriaQuery<T> query = getCriteriaBuilder().createQuery(entityClass);
524524
final JpaRoot<T> from = query.from(entityClass);
525-
query.where( from.get(persister.getIdentifierPropertyName()).in(ids) );
525+
query.where( from.get( persister.getIdentifierPropertyName() ).in(ids) );
526526
final List<T> resultList = createSelectionQuery(query).getResultList();
527-
final List<Object> idList = new ArrayList<>(resultList.size());
527+
final List<Object> idList = new ArrayList<>( resultList.size() );
528528
for (T entity : resultList) {
529529
idList.add( persister.getIdentifier(entity, this) );
530530
}
531-
final List<T> list = new ArrayList<>(ids.length);
531+
final List<T> list = new ArrayList<>( ids.size() );
532532
for (Object id : ids) {
533533
final int pos = idList.indexOf(id);
534534
list.add( pos < 0 ? null : resultList.get(pos) );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class FindAllTest {
2121
s.persist(new Record(456L,"hello mars"));
2222
});
2323
scope.inTransaction(s-> {
24-
List<Record> all = s.findAll(Record.class, 456L, 123L, 2L);
24+
List<Record> all = s.findAll(Record.class, List.of(456L, 123L, 2L));
2525
assertEquals("hello mars",all.get(0).message);
2626
assertEquals("hello earth",all.get(1).message);
2727
assertNull(all.get(2));

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/GetAllTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GetAllTest {
2121
s.insert(new Record(456L,"hello mars"));
2222
});
2323
scope.inStatelessTransaction(s-> {
24-
List<Record> all = s.getAll(Record.class, 456L, 123L, 2L);
24+
List<Record> all = s.getAll(Record.class, List.of(456L, 123L, 2L));
2525
assertEquals("hello mars",all.get(0).message);
2626
assertEquals("hello earth",all.get(1).message);
2727
assertNull(all.get(2));

0 commit comments

Comments
 (0)