revert to previous design with raw types

there is a problem with this approach: the user now gets unchecked
warnings since we've recently filled in the type args of the params
of some methods of Query and NativeQuery

but it's very hard to see how to fix the problem without breaking
compatibility
This commit is contained in:
Gavin King 2021-12-09 20:29:56 +01:00 committed by Steve Ebersole
parent a1e3f0cd6f
commit 0bb647e62b
7 changed files with 62 additions and 132 deletions

View File

@ -10,9 +10,6 @@ import java.util.List;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import org.hibernate.graph.RootGraph;
import org.hibernate.stat.SessionStatistics;
@ -1088,37 +1085,4 @@ public interface Session extends SharedSessionContract, EntityManager {
* @param listeners The listener(s) to add
*/
void addEventListeners(SessionEventListener... listeners);
// The following declarations just override the JPA return type with our
// Hibernate Query type, as required by the declaration in QueryProducer
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query getNamedQuery(String queryString);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query createQuery(String queryString);
@Override
<R> org.hibernate.query.Query<R> createQuery(String queryString, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query createNamedQuery(String queryString);
@Override
<R> org.hibernate.query.Query<R> createNamedQuery(String name, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.NativeQuery createNativeQuery(String queryString);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.NativeQuery createNativeQuery(String queryString, String resultSetMappingName);
@Override
<R> org.hibernate.query.Query<R> createQuery(CriteriaQuery<R> criteriaQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query createQuery(CriteriaUpdate updateQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
}

View File

@ -185,21 +185,6 @@ public interface SharedSessionContract extends QueryProducer, Closeable, Seriali
* @throws IllegalStateException if the StatelessSession has been closed
*/
HibernateCriteriaBuilder getCriteriaBuilder();
//
// @Override
// <T> org.hibernate.query.Query<T> createQuery(String queryString, Class<T> resultType);
//
// @Override
// <T> org.hibernate.query.Query<T> createQuery(CriteriaQuery<T> criteriaQuery);
//
// @Override
// <R> org.hibernate.query.Query<R> createQuery(CriteriaUpdate<?> updateQuery);
//
// @Override
// <R> org.hibernate.query.Query<R> createQuery(CriteriaDelete<?> deleteQuery);
//
// @Override
// <T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> resultType);
/**
* Controller for allowing users to perform JDBC related work using the Connection managed by this Session.

View File

@ -453,35 +453,35 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
@Override
public <T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery) {
return delegate.createQuery( criteriaQuery );
return queryDelegate().createQuery( criteriaQuery );
}
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(CriteriaUpdate updateQuery) {
return delegate.createQuery( updateQuery );
return queryDelegate().createQuery( updateQuery );
}
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(CriteriaDelete deleteQuery) {
return delegate.createQuery( deleteQuery );
return queryDelegate().createQuery( deleteQuery );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor getNamedQuery(String name) {
return queryDelegate().getNamedQuery( name );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor getNamedNativeQuery(String name) {
return queryDelegate().getNamedNativeQuery( name );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping) {
return queryDelegate().getNamedNativeQuery( name, resultSetMapping );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(String queryString) {
return queryDelegate().createQuery( queryString );
}
@ -491,7 +491,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return queryDelegate().createQuery( queryString, resultType );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createNamedQuery(String name) {
return queryDelegate().createNamedQuery( name );
}
@ -501,7 +501,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return queryDelegate().createNamedQuery( name, resultClass );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor createNativeQuery(String sqlString) {
return queryDelegate().createNativeQuery( sqlString );
}
@ -511,7 +511,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return queryDelegate().createNativeQuery( sqlString, resultClass );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName) {
return queryDelegate().createNativeQuery( sqlString, resultSetMappingName );
}

View File

@ -8,16 +8,11 @@ package org.hibernate.engine.spi;
import java.util.Map;
import java.util.Set;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
@ -118,39 +113,4 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem
*/
@Deprecated
void removeOrphanBeforeUpdates(String entityName, Object child);
// The following declarations just override the JPA return type with our
// Hibernate QueryImplementor type, as required by the declaration in
// QueryProducerImplementor
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor getNamedQuery(String queryString);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createQuery(String queryString);
@Override
<R> QueryImplementor<R> createQuery(String queryString, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createNamedQuery(String queryString);
@Override
<R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
NativeQueryImplementor createNativeQuery(String queryString);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
NativeQueryImplementor createNativeQuery(String queryString, String resultSetMappingName);
@Override
<R> QueryImplementor<R> createQuery(CriteriaQuery<R> criteriaQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createQuery(CriteriaUpdate updateQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createQuery(CriteriaDelete deleteQuery);
}

View File

@ -633,7 +633,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// dynamic HQL handling
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(String queryString) {
return createQuery( queryString, null );
}
@ -673,7 +673,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// dynamic native (SQL) query handling
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor createNativeQuery(String sqlString) {
checkOpen();
pulseTransactionCoordinator();
@ -715,7 +715,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName) {
checkOpen();
pulseTransactionCoordinator();
@ -749,12 +749,12 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// named query handling
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor getNamedQuery(String queryName) {
return buildNamedQuery( queryName, null );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createNamedQuery(String name) {
return buildNamedQuery( name, null );
}
@ -844,7 +844,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
protected void applyQuerySettingsAndHints(Query<?> query) {
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor getNamedNativeQuery(String queryName) {
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
.getNamedObjectRepository()
@ -857,7 +857,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) );
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public NativeQueryImplementor getNamedNativeQuery(String queryName, String resultSetMapping) {
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
.getNamedObjectRepository()
@ -996,7 +996,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(CriteriaUpdate criteriaUpdate) {
checkOpen();
try {
@ -1011,7 +1011,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
@Override @SuppressWarnings("rawtypes")
public QueryImplementor createQuery(CriteriaDelete criteriaDelete) {
checkOpen();
try {

View File

@ -31,7 +31,8 @@ public interface QueryProducer {
* defined with the given name or if the query string is
* found to be invalid
*/
<R> Query<R> getNamedQuery(String queryName);
@SuppressWarnings("rawtypes")
Query getNamedQuery(String queryName);
/**
* Create a {@link Query} instance for the given HQL/JPQL query string.
@ -42,7 +43,8 @@ public interface QueryProducer {
*
* @see jakarta.persistence.EntityManager#createQuery(String)
*/
<R> Query<R> createQuery(String queryString);
@SuppressWarnings("rawtypes")
Query createQuery(String queryString);
/**
* Create a typed {@link Query} instance for the given HQL/JPQL query string.
@ -69,7 +71,8 @@ public interface QueryProducer {
*
* @see jakarta.persistence.EntityManager#createNamedQuery(String)
*/
<R> Query<R> createNamedQuery(String name);
@SuppressWarnings("rawtypes")
Query createNamedQuery(String name);
/**
* The JPA-defined named, typed query creation method. This form can only
@ -98,7 +101,8 @@ public interface QueryProducer {
*
* @see jakarta.persistence.EntityManager#createNativeQuery(String)
*/
<R> NativeQuery<R> createNativeQuery(String sqlString);
@SuppressWarnings("rawtypes")
NativeQuery createNativeQuery(String sqlString);
/**
* Create a NativeQuery instance for the given native (SQL) query using
@ -125,7 +129,8 @@ public interface QueryProducer {
* @see jakarta.persistence.EntityManager#createNativeQuery(String,Class)
* @see jakarta.persistence.SqlResultSetMapping
*/
<R> NativeQuery<R> createNativeQuery(String sqlString, String resultSetMappingName);
@SuppressWarnings("rawtypes")
NativeQuery createNativeQuery(String sqlString, String resultSetMappingName);
/**
* Get a NativeQuery instance for a named native SQL query
@ -134,7 +139,8 @@ public interface QueryProducer {
*
* @return The NativeQuery instance for manipulation and execution
*/
<R> NativeQuery<R> getNamedNativeQuery(String name);
@SuppressWarnings("rawtypes")
NativeQuery getNamedNativeQuery(String name);
/**
* Get a NativeQuery instance for a named native SQL query
@ -143,7 +149,8 @@ public interface QueryProducer {
*
* @return The NativeQuery instance for manipulation and execution
*/
<R> NativeQuery<R> getNamedNativeQuery(String name, String resultSetMapping);
@SuppressWarnings("rawtypes")
NativeQuery getNamedNativeQuery(String name, String resultSetMapping);
/**
* Create a Query for the given JPA {@link CriteriaQuery}
@ -157,12 +164,14 @@ public interface QueryProducer {
*
* @see jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)
*/
<R> Query<R> createQuery(CriteriaUpdate<?> updateQuery);
@SuppressWarnings("rawtypes")
Query createQuery(CriteriaUpdate<?> updateQuery);
/**
* Create a Query for the given JPA {@link CriteriaDelete}
*
* @see jakarta.persistence.EntityManager#createQuery(CriteriaDelete)
*/
<R> Query<R> createQuery(CriteriaDelete<?> deleteQuery);
@SuppressWarnings("rawtypes")
Query createQuery(CriteriaDelete<?> deleteQuery);
}

View File

@ -6,6 +6,9 @@
*/
package org.hibernate.query.spi;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -26,33 +29,42 @@ public interface QueryProducerImplementor extends QueryProducer {
// todo : define list/scroll/iterate methods here...
@Override
<R> QueryImplementor<R> getNamedQuery(String queryName);
@Override @SuppressWarnings("rawtypes")
QueryImplementor getNamedQuery(String queryName);
@Override
<R> QueryImplementor<R> createQuery(String queryString);
@Override @SuppressWarnings("rawtypes")
QueryImplementor createQuery(String queryString);
@Override
<R> QueryImplementor<R> createQuery(String queryString, Class<R> resultClass);
@Override
<R> QueryImplementor<R> createNamedQuery(String name);
@Override @SuppressWarnings("rawtypes")
QueryImplementor createNamedQuery(String name);
@Override
<R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultClass);
@Override
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString);
@Override @SuppressWarnings("rawtypes")
NativeQueryImplementor createNativeQuery(String sqlString);
@Override
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString, Class<R> resultClass);
@Override
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString, String resultSetMappingName);
@Override @SuppressWarnings("rawtypes")
NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName);
@Override @SuppressWarnings("rawtypes")
NativeQueryImplementor getNamedNativeQuery(String name);
@Override @SuppressWarnings("rawtypes")
NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping);
@Override
<R> NativeQueryImplementor<R> getNamedNativeQuery(String name);
<R> QueryImplementor<R> createQuery(CriteriaQuery<R> criteriaQuery);
@Override
<R> NativeQueryImplementor<R> getNamedNativeQuery(String name, String resultSetMapping);
@Override @SuppressWarnings("rawtypes")
QueryImplementor createQuery(CriteriaUpdate<?> updateQuery);
@Override @SuppressWarnings("rawtypes")
QueryImplementor createQuery(CriteriaDelete<?> deleteQuery);
}