|
5 | 5 | package org.hibernate.orm.test.jpa.criteria;
|
6 | 6 |
|
7 | 7 | import java.util.ArrayList;
|
8 |
| -import java.util.Date; |
9 | 8 | import java.util.HashSet;
|
10 | 9 | import java.util.List;
|
11 | 10 | import jakarta.persistence.EntityManager;
|
|
21 | 20 |
|
22 | 21 | import org.hibernate.community.dialect.InformixDialect;
|
23 | 22 | import org.hibernate.dialect.CockroachDialect;
|
| 23 | +import org.hibernate.exception.SQLGrammarException; |
24 | 24 | import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
25 | 25 | import org.hibernate.orm.test.jpa.metamodel.Address;
|
26 | 26 | import org.hibernate.orm.test.jpa.metamodel.Alias;
|
|
37 | 37 | import org.hibernate.orm.test.jpa.metamodel.Spouse;
|
38 | 38 | import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate;
|
39 | 39 |
|
40 |
| -import org.hibernate.testing.FailureExpected; |
41 | 40 | import org.hibernate.testing.orm.junit.JiraKey;
|
42 | 41 | import org.hibernate.testing.orm.junit.SkipForDialect;
|
| 42 | +import org.hibernate.testing.transaction.TransactionUtil2; |
43 | 43 | import org.junit.Test;
|
44 | 44 |
|
45 | 45 | import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
46 | 46 | import static org.junit.Assert.assertEquals;
|
| 47 | +import static org.junit.Assert.fail; |
47 | 48 |
|
48 | 49 | /**
|
49 | 50 | * @author Steve Ebersole
|
@@ -282,36 +283,39 @@ public void testFunctionDialectFunctions() {
|
282 | 283 |
|
283 | 284 | @Test
|
284 | 285 | @JiraKey(value = "HHH-10737")
|
285 |
| - @FailureExpected(jiraKey = "HHH-10737") |
286 | 286 | public void testMissingDialectFunction() {
|
287 |
| - doInJPA( this::entityManagerFactory, em -> { |
| 287 | + TransactionUtil2.inTransaction( entityManagerFactory(), (em) -> { |
288 | 288 | Human human = new Human();
|
289 | 289 | human.setId( 200L );
|
290 | 290 | human.setName( "2" );
|
291 |
| - human.setBorn( new Date() ); |
292 | 291 | em.persist( human );
|
| 292 | + } ); |
293 | 293 |
|
294 |
| - em.getTransaction().commit(); |
295 |
| - |
| 294 | + TransactionUtil2.inTransaction( entityManagerFactory(), (em) -> { |
296 | 295 | CriteriaBuilder cb = em.getCriteriaBuilder();
|
297 |
| - CriteriaQuery<HumanDTO> criteria = cb.createQuery( HumanDTO.class ); |
| 296 | + CriteriaQuery<Long> criteria = cb.createQuery( Long.class ); |
| 297 | + |
298 | 298 | Root<Human> root = criteria.from( Human.class );
|
299 | 299 |
|
300 |
| - criteria.select( |
301 |
| - cb.construct( |
302 |
| - HumanDTO.class, |
303 |
| - root.get( Human_.id ), |
| 300 | + criteria.select( cb.count( cb.literal( 1 ) ) ); |
| 301 | + |
| 302 | + criteria.where( |
| 303 | + cb.equal( |
304 | 304 | root.get( Human_.name ),
|
305 | 305 | cb.function(
|
306 |
| - "convert", |
| 306 | + "does_not_exist", |
307 | 307 | String.class,
|
308 |
| - root.get( Human_.born ), |
309 |
| - cb.literal( 110 ) |
| 308 | + root.get( Human_.id ) |
310 | 309 | )
|
311 | 310 | )
|
312 | 311 | );
|
313 | 312 |
|
314 |
| - em.createQuery( criteria ).getResultList(); |
| 313 | + try { |
| 314 | + em.createQuery( criteria ).getResultList(); |
| 315 | + fail( "Expecting a SQLGrammarException" ); |
| 316 | + } |
| 317 | + catch (SQLGrammarException expected) { |
| 318 | + } |
315 | 319 | } );
|
316 | 320 | }
|
317 | 321 |
|
|
0 commit comments