diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java index 911386e149..f896a504b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java @@ -15,6 +15,7 @@ import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.persistence.criteria.SetJoin; import javax.persistence.metamodel.EntityType; @@ -35,8 +36,7 @@ import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.ShelfLife; import org.hibernate.jpa.test.metamodel.Spouse; import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; -import org.hibernate.query.criteria.internal.CriteriaBuilderImpl; -import org.hibernate.query.criteria.internal.predicate.ComparisonPredicate; +import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate; import org.hibernate.testing.FailureExpected; import org.hibernate.testing.RequiresDialect; @@ -76,33 +76,33 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); - CriteriaQuery cquery = cb.createQuery( Integer.class ); + CriteriaQuery cquery = cb.createQuery( Integer.class ); Root product = cquery.from( Product.class ); EntityType Product_ = mm.entity( Product.class ); cquery.select( cb.toInteger( product.get( - Product_.getSingularAttribute("quantity", Integer.class)) + Product_.getSingularAttribute( "quantity", Integer.class ) ) ) ); - ComparisonPredicate predicate = (ComparisonPredicate) cb.equal( + SqmComparisonPredicate predicate = (SqmComparisonPredicate) cb.equal( product.get( Product_.getSingularAttribute( "partNumber", Long.class ) ), 373767373 ); - assertEquals( Long.class, predicate.getRightHandOperand().getJavaType() ); + assertEquals( Long.class, predicate.getLeftHandExpression().getJavaType() ); cquery.where( predicate ); em.createQuery( cquery ).getResultList(); - predicate = (ComparisonPredicate) cb.ge( + predicate = (SqmComparisonPredicate) cb.ge( cb.length( product.get( Product_.getSingularAttribute( "name", String.class ) ) ), 4L ); - assertEquals( Integer.class, predicate.getRightHandOperand().getJavaType() ); + assertEquals( Integer.class, predicate.getLeftHandExpression().getJavaType() ); cquery.where( predicate ); em.createQuery( cquery ).getResultList(); @@ -134,13 +134,13 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); EntityType Phone_ = mm.entity( Phone.class ); CriteriaQuery cquery = cb.createQuery( Phone.class ); Root phone = cquery.from( Phone.class ); - ComparisonPredicate predicate = (ComparisonPredicate) cb.equal( + Predicate predicate = cb.equal( phone.get( Phone_.getSingularAttribute( "address", Address.class ) ), address ); @@ -156,26 +156,26 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { public void testTypeConversion() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); EntityType Product_ = mm.entity( Product.class ); // toFloat - CriteriaQuery floatQuery = cb.createQuery( Float.class ); + CriteriaQuery floatQuery = cb.createQuery( Float.class ); Root product = floatQuery.from( Product.class ); floatQuery.select( cb.toFloat( - product.get(Product_.getSingularAttribute("quantity", Integer.class)) + product.get( Product_.getSingularAttribute( "quantity", Integer.class ) ) ) ); em.createQuery( floatQuery ).getResultList(); // toDouble - CriteriaQuery doubleQuery = cb.createQuery(Double.class); + CriteriaQuery doubleQuery = cb.createQuery( Double.class ); product = doubleQuery.from( Product.class ); doubleQuery.select( cb.toDouble( - product.get(Product_.getSingularAttribute("quantity", Integer.class)) + product.get( Product_.getSingularAttribute( "quantity", Integer.class ) ) ) ); em.createQuery( doubleQuery ).getResultList(); @@ -188,21 +188,21 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { public void testConstructor() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); - CriteriaQuery cquery = cb.createQuery(Customer.class); - Root customer = cquery.from(Customer.class); + CriteriaQuery cquery = cb.createQuery( Customer.class ); + Root customer = cquery.from( Customer.class ); EntityType Customer_ = customer.getModel(); cquery.select( cb.construct( Customer.class, - customer.get(Customer_.getSingularAttribute("id", String.class)), - customer.get(Customer_.getSingularAttribute("name", String.class)) + customer.get( Customer_.getSingularAttribute( "id", String.class ) ), + customer.get( Customer_.getSingularAttribute( "name", String.class ) ) ) ); - TypedQuery tq = em.createQuery(cquery); + TypedQuery tq = em.createQuery( cquery ); tq.getResultList(); em.getTransaction().commit(); @@ -217,7 +217,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery( Customer.class ); Root r = cq.from( Customer.class ); cq.multiselect( @@ -235,20 +235,20 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { public void testDateTimeFunctions() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); - CriteriaQuery dateQuery = cb.createQuery(java.sql.Date.class); + CriteriaQuery dateQuery = cb.createQuery( java.sql.Date.class ); dateQuery.from( Customer.class ); dateQuery.select( cb.currentDate() ); em.createQuery( dateQuery ).getResultList(); - CriteriaQuery timeQuery = cb.createQuery(java.sql.Time.class); + CriteriaQuery timeQuery = cb.createQuery( java.sql.Time.class ); timeQuery.from( Customer.class ); timeQuery.select( cb.currentTime() ); em.createQuery( timeQuery ).getResultList(); - CriteriaQuery tsQuery = cb.createQuery(java.sql.Timestamp.class); + CriteriaQuery tsQuery = cb.createQuery( java.sql.Timestamp.class ); tsQuery.from( Customer.class ); tsQuery.select( cb.currentTimestamp() ); em.createQuery( tsQuery ).getResultList(); @@ -261,7 +261,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { public void testFunctionDialectFunctions() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteria = cb.createQuery( Long.class ); criteria.select( cb.count( cb.literal( 1 ) ) ); Root root = criteria.from( Customer.class ); @@ -281,36 +281,36 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().commit(); em.close(); } - + @Test @TestForIssue(jiraKey = "HHH-10737") - @FailureExpected( jiraKey = "HHH-10737" ) + @FailureExpected(jiraKey = "HHH-10737") public void testMissingDialectFunction() { doInJPA( this::entityManagerFactory, em -> { Human human = new Human(); - human.setId(200L); - human.setName("2"); - human.setBorn(new Date()); - em.persist(human); + human.setId( 200L ); + human.setName( "2" ); + human.setBorn( new Date() ); + em.persist( human ); em.getTransaction().commit(); - CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteria = cb.createQuery( HumanDTO.class ); Root root = criteria.from( Human.class ); criteria.select( - cb.construct( - HumanDTO.class, - root.get(Human_.id), - root.get(Human_.name), - cb.function( - "convert", - String.class, - root.get(Human_.born), - cb.literal(110) + cb.construct( + HumanDTO.class, + root.get( Human_.id ), + root.get( Human_.name ), + cb.function( + "convert", + String.class, + root.get( Human_.born ), + cb.literal( 110 ) + ) ) - ) ); em.createQuery( criteria ).getResultList(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NativeQueryOrdinalParametersTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NativeQueryOrdinalParametersTest.java index 39824843d1..6520d53ce0 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NativeQueryOrdinalParametersTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/NativeQueryOrdinalParametersTest.java @@ -21,7 +21,6 @@ import org.hibernate.Session; import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.query.NativeQuery; -import org.hibernate.query.spi.NativeQueryImplementor; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; @@ -93,24 +92,24 @@ public class NativeQueryOrdinalParametersTest extends BaseEntityManagerFunctiona final String sqlString = "SELECT * FROM GAME g WHERE title = ?"; doInJPA( this::entityManagerFactory, entityManager -> { - NativeQuery sqlQuery = entityManager.unwrap( Session.class ).createSQLQuery( sqlString ); - sqlQuery.setString( 1, "Super Mario Brothers" ).setCacheable( true ); + NativeQuery sqlQuery = entityManager.unwrap( Session.class ).createNativeQuery( sqlString ); + sqlQuery.setParameter( 1, "Super Mario Brothers" ).setCacheable( true ); List results = sqlQuery.list(); assertEquals( 1, results.size() ); - NativeQueryImplementor query = (NativeQueryImplementor) entityManager.createNativeQuery( sqlString ); - query.setString( 1, "Super Mario Brothers" ); + NativeQuery query = (NativeQuery) entityManager.createNativeQuery( sqlString ); + query.setParameter( 1, "Super Mario Brothers" ); List list = query.list(); assertEquals( 1, list.size() ); - sqlQuery = entityManager.unwrap( Session.class ).createSQLQuery( sqlString ); - sqlQuery.setString( 1, "Super Mario Brothers" ).setCacheable( true ); + sqlQuery = entityManager.unwrap( Session.class ).createNativeQuery( sqlString ); + sqlQuery.setParameter( 1, "Super Mario Brothers" ).setCacheable( true ); results = sqlQuery.list(); assertEquals( 1, results.size() ); - query.setString( 1, "Super Mario Brothers" ); + query.setParameter( 1, "Super Mario Brothers" ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/TupleNativeQueryTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/TupleNativeQueryTest.java index 25eb4f514f..f3db40df62 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/TupleNativeQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/TupleNativeQueryTest.java @@ -2,7 +2,9 @@ package org.hibernate.jpa.test.query; import org.hibernate.dialect.H2Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.query.spi.NativeQueryImplementor; +import org.hibernate.query.sql.internal.NativeQueryImpl; +import org.hibernate.query.sql.spi.NativeQueryImplementor; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.junit.After; @@ -723,7 +725,10 @@ public class TupleNativeQueryTest extends BaseEntityManagerFunctionalTestCase { @SuppressWarnings("unchecked") private List getStreamedTupleAliasedResult(EntityManager entityManager) { - NativeQueryImplementor query = (NativeQueryImplementor) entityManager.createNativeQuery("SELECT id AS alias1, firstname AS alias2 FROM users", Tuple.class); + NativeQueryImpl query = (NativeQueryImpl) entityManager.createNativeQuery( + "SELECT id AS alias1, firstname AS alias2 FROM users", + Tuple.class + ); return (List) query.stream().collect(Collectors.toList()); } @@ -740,7 +745,7 @@ public class TupleNativeQueryTest extends BaseEntityManagerFunctionalTestCase { @SuppressWarnings("unchecked") private List getStreamedTupleResult(EntityManager entityManager) { - NativeQueryImplementor query = (NativeQueryImplementor) entityManager.createNativeQuery("SELECT id, firstname FROM users", Tuple.class); + NativeQueryImplementor query = (NativeQueryImplementor) entityManager.createNativeQuery( "SELECT id, firstname FROM users", Tuple.class); return (List) query.stream().collect(Collectors.toList()); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/formula/FormulaWithColumnTypesTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/formula/FormulaWithColumnTypesTest.java index 49a0402068..54d3fb4cc8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/formula/FormulaWithColumnTypesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/formula/FormulaWithColumnTypesTest.java @@ -18,7 +18,6 @@ import org.hibernate.Transaction; import org.hibernate.annotations.Formula; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.criterion.Order; import org.hibernate.dialect.H2Dialect; import org.hibernate.testing.RequiresDialect; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java index 91aac49d78..419fec8f1f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdOnSingleManyToOneTest.java @@ -8,13 +8,15 @@ package org.hibernate.test.annotations.naturalid; import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaQuery; + import org.junit.After; import org.junit.Test; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Restrictions; import org.hibernate.metadata.ClassMetadata; import org.hibernate.stat.Statistics; import org.hibernate.testing.TestForIssue; @@ -94,7 +96,8 @@ public class NaturalIdOnSingleManyToOneTest extends BaseCoreFunctionalTestCase { s = openSession(); tx = s.beginTransaction(); - Criteria criteria = s.createCriteria( NaturalIdOnManyToOne.class ); + CriteriaQuery query = s.getCriteriaBuilder().createQuery( NaturalIdOnManyToOne.class ); + query. criteria.add( Restrictions.naturalId().set( "citizen", c1 ) ); criteria.setCacheable( true ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdTest.java index 53ca5022f9..d842223336 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/NaturalIdTest.java @@ -8,13 +8,16 @@ package org.hibernate.test.annotations.naturalid; import java.util.List; -import org.hibernate.Criteria; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; + import org.hibernate.NaturalIdLoadAccess; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Restrictions; import org.hibernate.metadata.ClassMetadata; +import org.hibernate.query.Query; import org.hibernate.stat.Statistics; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -315,10 +318,14 @@ public class NaturalIdTest extends BaseCoreFunctionalTestCase { } private State getState(Session s, String name) { - Criteria criteria = s.createCriteria( State.class ); - criteria.add( Restrictions.eq( "name", name ) ); - criteria.setCacheable( true ); - return (State) criteria.list().get( 0 ); + final CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( State.class ); + Root root = criteria.from( State.class ); + criteria.select( root ).where( criteriaBuilder.equal( root.get( "name" ), name ) ); + + Query query = s.createQuery( criteria ); + query.setCacheable( true ); + return query.list().get( 0 ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java index 2c8dc169d4..14e0eb5073 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java @@ -10,7 +10,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.TeradataDialect; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java index c1ba41ed72..0814a1220f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java @@ -10,9 +10,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; - import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; import org.hibernate.LockMode; import org.hibernate.LockOptions; @@ -20,21 +24,23 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Order; -import org.hibernate.criterion.Projections; import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.exception.LockTimeoutException; -import org.junit.Test; +import org.hibernate.query.Query; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +//import org.hibernate.criterion.Order; +//import org.hibernate.criterion.Projections; + /** * used driver hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver * @@ -257,14 +263,24 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase { session.clear(); // count number of products in each category - List result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" ) - .setProjection( - Projections.projectionList() - .add( Projections.groupProperty( "c.id" ) ) - .add( Projections.countDistinct( "p.id" ) ) - ) - .addOrder( Order.asc( "c.id" ) ) - .setFirstResult( 1 ).setMaxResults( 3 ).list(); +// List result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" ) +// .setProjection( +// Projections.projectionList() +// .add( Projections.groupProperty( "c.id" ) ) +// .add( Projections.countDistinct( "p.id" ) ) +// ) +// .addOrder( Order.asc( "c.id" ) ) +// .setFirstResult( 1 ).setMaxResults( 3 ).list(); + + CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Object[].class ); + Root root = criteria.from( Category.class ); + Join products = root.join( "products", JoinType.INNER ); + criteria.multiselect( root.get( "id" ), criteriaBuilder.countDistinct( products.get( "id" ) ) ); + criteria.orderBy( criteriaBuilder.asc( root.get( "id" ) ) ); + Query query = session.createQuery( criteria ); + + List result = query.setFirstResult( 1 ).setMaxResults( 3 ).list(); assertEquals( 2, result.size() ); assertArrayEquals( new Object[] { 2, 2L }, result.get( 0 ) ); // two products of second category diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java index e13aafa0bc..4098ce1c38 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java @@ -20,7 +20,7 @@ import java.util.Map; import org.hibernate.Hibernate; import org.hibernate.HibernateException; -import org.hibernate.Query; +import org.hibernate.query.Query; import org.hibernate.QueryException; import org.hibernate.ScrollableResults; import org.hibernate.Session; @@ -946,7 +946,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { // simple syntax checking... Session s = openSession(); s.beginTransaction(); - s.createQuery( "from Human h where h.nickName = '1' || 'ov' || 'tha' || 'few'" ).list(); + s.createQuery( "from Human h wherFe h.nickName = '1' || 'ov' || 'tha' || 'few'" ).list(); s.getTransaction().commit(); s.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/naturalid/ImmutableNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/naturalid/ImmutableNaturalIdTest.java index 3342c07075..2c5bbdd0a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/naturalid/ImmutableNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/naturalid/ImmutableNaturalIdTest.java @@ -15,7 +15,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.criterion.Restrictions; import org.hibernate.test.jpa.AbstractJPATest; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java index 0cd4e68511..32f46186bc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintHANATest.java @@ -19,9 +19,14 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Fetch; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.Query; @@ -29,6 +34,7 @@ import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; +import org.hibernate.test.annotations.naturalid.State; import org.junit.Test; /** @@ -118,10 +124,21 @@ public class QueryHintHANATest extends BaseNonConfigCoreFunctionalTestCase { // test Criteria doInHibernate( this::sessionFactory, s -> { - Criteria criteria = s.createCriteria( Employee.class ) - .addQueryHint( "NO_CS_JOIN" ) - .createCriteria( "department" ).add( Restrictions.eq( "name", "Sales" ) ); - List results = criteria.list(); + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Employee.class ); + Root root = criteria.from( Employee.class ); + Join department = root.join( "department", JoinType.INNER ); + criteria.select( root ).where( criteriaBuilder.equal( department.get("name"), "Sales" ) ); + + Query query = s.createQuery( criteria ); + query.addQueryHint( "NO_CS_JOIN" ); + + List results = query.list(); + +// Criteria criteria = s.createCriteria( Employee.class ) +// .addQueryHint( "NO_CS_JOIN" ) +// .createCriteria( "department" ).add( Restrictions.eq( "name", "Sales" ) ); +// List results = criteria.list(); assertEquals( results.size(), 2 ); } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintSQLServer2012Test.java b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintSQLServer2012Test.java index 5490ccdf19..a476e3e5b9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintSQLServer2012Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintSQLServer2012Test.java @@ -12,12 +12,16 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; import org.hibernate.query.Query; import org.hibernate.Session; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.SQLServer2012Dialect; import org.hibernate.testing.RequiresDialect; @@ -107,9 +111,18 @@ public class QueryHintSQLServer2012Test extends BaseCoreFunctionalTestCase { // test Criteria s.getTransaction().begin(); - Criteria criteria = s.createCriteria( Employee.class ).addQueryHint( "MAXDOP 2" ).createCriteria( "department" ) - .add( Restrictions.eq( "name", "Sales" ) ); - results = criteria.list(); + + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Employee.class ); + Root root = criteria.from( Employee.class ); + Join departement = root.join( "departement", JoinType.INNER ); + criteria.select( root ).where( criteriaBuilder.equal( departement.get( "name" ), "Sales" ) ); +// Criteria criteria = s.createCriteria( Employee.class ).addQueryHint( "MAXDOP 2" ).createCriteria( "department" ) +// .add( Restrictions.eq( "name", "Sales" ) ); +// results = criteria.list(); + Query criteriaQuery = s.createQuery( criteria ); + criteriaQuery.addQueryHint( "MAXDOP 2" ); + results = criteriaQuery.list(); s.getTransaction().commit(); s.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java index a3fa9cda80..1aeb060acd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/queryhint/QueryHintTest.java @@ -13,9 +13,12 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.Root; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.Query; @@ -117,10 +120,17 @@ public class QueryHintTest extends BaseNonConfigCoreFunctionalTestCase { // test Criteria doInHibernate( this::sessionFactory, s -> { - Criteria criteria = s.createCriteria( Employee.class ) - .addQueryHint( "ALL_ROWS" ) - .createCriteria( "department" ).add( Restrictions.eq( "name", "Sales" ) ); - List results = criteria.list(); + final CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Employee.class ); + Root root = criteria.from( Employee.class ); + Join departmentJoin = root.join( "department" ); + criteria.select( root ).where( criteriaBuilder.equal( departmentJoin.get( "name" ),"Sales" ) ); +// Criteria criteria = s.createCriteria( Employee.class ) +// .addQueryHint( "ALL_ROWS" ) +// .createCriteria( "department" ).add( Restrictions.eq( "name", "Sales" ) ); + Query query = s.createQuery( criteria ); + query.addQueryHint( "ALL_ROWS" ); + List results = query.list(); assertEquals(results.size(), 2); } );