From 7a51b12cbb9a33c4569e8fa8cac0e234c65bd9ba Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 5 Feb 2019 14:30:46 -0800 Subject: [PATCH] HHH-13194 : Some methods returning org.hibernate.query.Query are not defined for StatelessSession HHH-13194 : Remove @Incubating from org.hibernate.query.Query --- .../src/main/java/org/hibernate/Session.java | 5 -- .../org/hibernate/SharedSessionContract.java | 6 +++ .../java/org/hibernate/StatelessSession.java | 5 ++ .../main/java/org/hibernate/query/Query.java | 3 -- .../hibernate/test/stateless/Contact.hbm.xml | 2 + .../stateless/StatelessSessionQueryTest.java | 49 +++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 10ae861c2e..70ab75a9fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -1161,9 +1161,6 @@ public interface Session extends SharedSessionContract, EntityManager, Hibernate */ void addEventListeners(SessionEventListener... listeners); - @Override - org.hibernate.query.Query createQuery(String queryString); - @Override org.hibernate.query.Query createQuery(String queryString, Class resultType); @@ -1176,8 +1173,6 @@ public interface Session extends SharedSessionContract, EntityManager, Hibernate @Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery); - @Override - org.hibernate.query.Query getNamedQuery(String queryName); org.hibernate.query.Query createNamedQuery(String name, Class resultType); diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java index e92d7bdb87..e5e49f95ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java @@ -67,6 +67,12 @@ public interface SharedSessionContract extends QueryProducer, Serializable { */ Transaction getTransaction(); + @Override + org.hibernate.query.Query createQuery(String queryString); + + @Override + org.hibernate.query.Query getNamedQuery(String queryName); + /** * Gets a ProcedureCall based on a named template * diff --git a/hibernate-core/src/main/java/org/hibernate/StatelessSession.java b/hibernate-core/src/main/java/org/hibernate/StatelessSession.java index 2263501c49..8a15cf1f75 100755 --- a/hibernate-core/src/main/java/org/hibernate/StatelessSession.java +++ b/hibernate-core/src/main/java/org/hibernate/StatelessSession.java @@ -10,6 +10,8 @@ import java.io.Closeable; import java.io.Serializable; import java.sql.Connection; +import org.hibernate.query.NativeQuery; + /** * A command-oriented API for performing bulk operations against a database. *

@@ -170,4 +172,7 @@ public interface StatelessSession extends SharedSessionContract, AutoCloseable, */ @Deprecated Connection connection(); + + @Override + NativeQuery createSQLQuery(String queryString); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index e117152e21..20066bf584 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -29,12 +29,10 @@ import javax.persistence.TypedQuery; import org.hibernate.CacheMode; import org.hibernate.FlushMode; -import org.hibernate.Incubating; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; -import org.hibernate.graph.Graph; import org.hibernate.graph.GraphSemantic; import org.hibernate.graph.RootGraph; import org.hibernate.transform.ResultTransformer; @@ -69,7 +67,6 @@ import org.hibernate.type.Type; * @author Steve Ebersole * @author Gavin King */ -@Incubating @SuppressWarnings("UnusedDeclaration") public interface Query extends TypedQuery, org.hibernate.Query, CommonQueryContract { /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml index e3f69ec966..ce29182757 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml @@ -16,6 +16,8 @@ + from Contact + diff --git a/hibernate-core/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java index 40bfe390c9..9e99980f33 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java @@ -16,7 +16,10 @@ import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.dialect.AbstractHANADialect; +import org.hibernate.query.NativeQuery; + import org.hibernate.testing.SkipForDialect; +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -72,6 +75,52 @@ public class StatelessSessionQueryTest extends BaseCoreFunctionalTestCase { testData.cleanData(); } + @Test + @TestForIssue( jiraKey = "HHH-13194") + @SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column") + public void testDeprecatedQueryApis() { + TestData testData=new TestData(); + testData.createData(); + + final String queryString = "from Contact c join fetch c.org join fetch c.org.country"; + StatelessSession s = sessionFactory().openStatelessSession(); + + org.hibernate.Query query = s.createQuery( queryString ); + assertEquals( 1, query.getResultList().size() ); + + query = s.getNamedQuery( Contact.class.getName() + ".contacts" ); + assertEquals( 1, query.getResultList().size() ); + + org.hibernate.SQLQuery sqlQuery = s.createSQLQuery( "select id from Contact" ); + assertEquals( 1, sqlQuery.getResultList().size() ); + + s.close(); + testData.cleanData(); + } + + @Test + @TestForIssue( jiraKey = "HHH-13194") + @SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column") + public void testNewQueryApis() { + TestData testData=new TestData(); + testData.createData(); + + final String queryString = "from Contact c join fetch c.org join fetch c.org.country"; + StatelessSession s = sessionFactory().openStatelessSession(); + + org.hibernate.query.Query query = s.createQuery( queryString ); + assertEquals( 1, query.getResultList().size() ); + + query = s.getNamedQuery( Contact.class.getName() + ".contacts" ); + assertEquals( 1, query.getResultList().size() ); + + org.hibernate.query.NativeQuery sqlQuery = s.createSQLQuery( "select id from Contact" ); + assertEquals( 1, sqlQuery.getResultList().size() ); + + s.close(); + testData.cleanData(); + } + private class TestData{ List list = new ArrayList(); public void createData(){