From 711aaec3c909b87f2a29c7e86224dc187e0ed166 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 18 Jul 2019 17:41:21 +0100 Subject: [PATCH] 6 - SQM based on JPA type system --- .../test/batchfetch/BatchFetchTest.java | 2 +- .../test/onetoone/link/OneToOneLinkTest.java | 8 +++-- .../org/hibernate/test/ops/MergeTest.java | 29 +++++++++++-------- .../sql/NativeQueryScrollableResults.java | 2 +- ...ativeQueryDoesNotSupportIterationTest.java | 0 5 files changed, 24 insertions(+), 17 deletions(-) rename hibernate-core/src/{test/java => test_legacy}/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java (100%) diff --git a/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchTest.java b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchTest.java index db004a0876..e49907940c 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchTest.java @@ -103,7 +103,7 @@ public class BatchFetchTest extends BaseCoreFunctionalTestCase { s.clear(); - Iterator iter = s.createQuery( "from Model" ).iterate(); + Iterator iter = s.createQuery( "from Model" ).list().iterator(); list = new ArrayList(); while ( iter.hasNext() ) { list.add( iter.next() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java index 8a7b7963a0..6455cdae63 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/link/OneToOneLinkTest.java @@ -19,6 +19,8 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.type.DateType; + import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -57,9 +59,9 @@ public class OneToOneLinkTest extends BaseCoreFunctionalTestCase { assertNull( e.getPerson().getCustomer() ); s.clear(); - e = (Employee) s.createQuery("from Employee e where e.person.dob = :date") - .setDate("date", new Date() ) - .uniqueResult(); + e = (Employee) s.createQuery( "from Employee e where e.person.dob = :date" ) + .setParameter( "date", new Date(), DateType.INSTANCE ) + .uniqueResult(); assertEquals( e.getPerson().getName(), "Gavin King" ); assertFalse( Hibernate.isInitialized( e.getPerson() ) ); assertNull( e.getPerson().getCustomer() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/ops/MergeTest.java b/hibernate-core/src/test/java/org/hibernate/test/ops/MergeTest.java index 00cb25ed40..d74c4e16c5 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/ops/MergeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ops/MergeTest.java @@ -7,6 +7,9 @@ package org.hibernate.test.ops; import javax.persistence.PersistenceException; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -626,9 +629,7 @@ public class MergeTest extends AbstractOperationTestCase { s.beginTransaction(); assertEquals( Long.valueOf( 2 ), - s.createCriteria( NumberedNode.class ) - .setProjection( Projections.rowCount() ) - .uniqueResult() + getNumneredNodeRowCount( s ) ); s.getTransaction().commit(); s.close(); @@ -636,6 +637,14 @@ public class MergeTest extends AbstractOperationTestCase { cleanup(); } + private Long getNumneredNodeRowCount(Session s ){ + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Long.class ); + Root root = criteria.from( NumberedNode.class ); + criteria.select( criteriaBuilder.count( root ) ); + return s.createQuery( criteria ).uniqueResult(); + } + @Test public void testMergeManagedUninitializedCollection() { Session s = openSession(); @@ -669,9 +678,7 @@ public class MergeTest extends AbstractOperationTestCase { tx = s.beginTransaction(); assertEquals( Long.valueOf( 2 ), - s.createCriteria( NumberedNode.class ) - .setProjection( Projections.rowCount() ) - .uniqueResult() + getNumneredNodeRowCount( s ) ); tx.commit(); @@ -714,9 +721,7 @@ public class MergeTest extends AbstractOperationTestCase { tx = s.beginTransaction(); assertEquals( Long.valueOf( 2 ), - s.createCriteria(NumberedNode.class) - .setProjection( Projections.rowCount() ) - .uniqueResult() + getNumneredNodeRowCount( s ) ); tx.commit(); @@ -749,7 +754,7 @@ public class MergeTest extends AbstractOperationTestCase { } @Test - public void testDeleteAndMerge() throws Exception { + public void testDeleteAndMerge() { Session s = openSession(); s.getTransaction().begin(); Employer jboss = new Employer(); @@ -759,7 +764,7 @@ public class MergeTest extends AbstractOperationTestCase { s.getTransaction().begin(); Employer otherJboss; - otherJboss = (Employer) s.get( Employer.class, jboss.getId() ); + otherJboss = s.get( Employer.class, jboss.getId() ); s.delete( otherJboss ); s.getTransaction().commit(); s.clear(); @@ -775,7 +780,7 @@ public class MergeTest extends AbstractOperationTestCase { @SuppressWarnings( {"unchecked"}) @Test @SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column") - public void testMergeManyToManyWithCollectionDeference() throws Exception { + public void testMergeManyToManyWithCollectionDeference() { // setup base data... Session s = openSession(); Transaction tx = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryScrollableResults.java b/hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryScrollableResults.java index 526a4f48d6..f2876f1c9f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryScrollableResults.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryScrollableResults.java @@ -82,7 +82,7 @@ public class NativeQueryScrollableResults extends BaseCoreFunctionalTestCase { .setParameter( "bigValues", params ); try (ScrollableResults scroll = query.scroll()) { while ( scroll.next() ) { - assertThat( scroll.get()[0], not( nullValue()) ); + assertThat( scroll.get(), not( nullValue()) ); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java similarity index 100% rename from hibernate-core/src/test/java/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java rename to hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java