BAEL-7068: Cast Query.list() to List<Type> in Hibernate (#15484)

This commit is contained in:
ACHRAF TAITAI 2023-12-30 09:50:54 +01:00 committed by GitHub
parent 164ef67325
commit 4c517ab0de
1 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package com.baeldung.hibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@ -74,5 +75,13 @@ public class CustomClassIntegrationTest {
assertEquals("Sales", result.getDepartmentName());
}
@Test
public void whenCastResultQueryToList_ThenListOfResultIsReturned() {
Query<Result> query = session.createQuery("select new com.baeldung.hibernate.pojo.Result(m.name, m.department.name) "
+ "from DeptEmployee m");
List<Result> results = query.list();
assertNotNull(results);
assertEquals(1, results.size());
}
}