|
24 | 24 | import org.hibernate.cfg.Environment;
|
25 | 25 | import org.hibernate.dialect.H2Dialect;
|
26 | 26 | import org.hibernate.dialect.MySQLDialect;
|
| 27 | +import org.hibernate.orm.test.query.NativeQueryLimitOffsetTest; |
27 | 28 | import org.hibernate.orm.test.sql.hand.Dimension;
|
28 | 29 | import org.hibernate.orm.test.sql.hand.Employment;
|
29 | 30 | import org.hibernate.orm.test.sql.hand.Group;
|
|
38 | 39 | import org.hibernate.query.NativeQuery;
|
39 | 40 | import org.hibernate.query.Query;
|
40 | 41 | import org.hibernate.query.ResultListTransformer;
|
| 42 | +import org.hibernate.testing.orm.junit.Jira; |
| 43 | +import org.hibernate.testing.orm.junit.JiraGroup; |
41 | 44 | import org.hibernate.transform.ResultTransformer;
|
42 | 45 | import org.hibernate.transform.Transformers;
|
43 | 46 | import org.hibernate.type.StandardBasicTypes;
|
|
59 | 62 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
60 | 63 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
61 | 64 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
| 65 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
62 | 66 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
63 | 67 | import static org.junit.jupiter.api.Assertions.fail;
|
64 | 68 |
|
@@ -938,6 +942,32 @@ public void testAliasToBeanMap(SessionFactoryScope scope) {
|
938 | 942 | );
|
939 | 943 | }
|
940 | 944 |
|
| 945 | + @Test |
| 946 | + @JiraGroup( |
| 947 | + { |
| 948 | + @Jira("https://hibernate.atlassian.net/browse/HHH-19376"), |
| 949 | + @Jira("https://hibernate.atlassian.net/browse/HHH-19383") |
| 950 | + } |
| 951 | + ) |
| 952 | + public void testMutateResultSetMapping(SessionFactoryScope scope) { |
| 953 | + scope.inTransaction( |
| 954 | + session -> { |
| 955 | + String sql = "SELECT p.*, COUNT(*) OVER() AS total_count " |
| 956 | + + "FROM Person p " |
| 957 | + + "WHERE p.name ILIKE :name " |
| 958 | + + "ORDER BY p.id"; |
| 959 | + // Declare Person as result type |
| 960 | + NativeQuery<NativeQueryLimitOffsetTest.Person> query = session.createNativeQuery(sql, NativeQueryLimitOffsetTest.Person.class); |
| 961 | + query.setParameter("name", "Ja%"); |
| 962 | + query.setMaxResults(2); |
| 963 | + query.setFirstResult(0); |
| 964 | + // Now mutate the result set mapping and verify an Exception is thrown |
| 965 | + assertThrows( IllegalArgumentException.class, |
| 966 | + () -> query.addScalar( "total_count", StandardBasicTypes.LONG).list() ); |
| 967 | + } |
| 968 | + ); |
| 969 | + } |
| 970 | + |
941 | 971 | private String buildLongString(int size, char baseChar) {
|
942 | 972 | StringBuilder buff = new StringBuilder();
|
943 | 973 | for( int i = 0; i < size; i++ ) {
|
|
0 commit comments