From 4f72bd0cef6380ab3765242673d68ae79c643ecf Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 28 Apr 2016 15:00:33 +0100 Subject: [PATCH] Fix guessType() method refactoring --- .../spi/SessionFactoryDelegatingImpl.java | 5 +++ .../internal/SessionFactoryImpl.java | 6 +++- .../internal/CriteriaBuilderImpl.java | 36 ++++++------------- .../query/internal/AbstractProducedQuery.java | 25 +------------ .../QueryParameterBindingTypeResolver.java | 1 + 5 files changed, 23 insertions(+), 50 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index ba0feab88a..5ebc7e476f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -508,4 +508,9 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, public Type resolveParameterBindType(Object bindValue) { return delegate.resolveParameterBindType( bindValue ); } + + @Override + public Type resolveParameterBindType(Class clazz) { + return delegate.resolveParameterBindType( clazz ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index db774eedee..a6ffa95b70 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -967,7 +967,11 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { return null; } - final Class clazz = HibernateProxyHelper.getClassWithoutInitializingProxy( bindValue ); + return resolveParameterBindType( HibernateProxyHelper.getClassWithoutInitializingProxy( bindValue ) ); + } + + @Override + public Type resolveParameterBindType(Class clazz){ String typename = clazz.getName(); Type type = getTypeResolver().heuristicType( typename ); boolean serializable = type != null && type instanceof SerializableType; diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/CriteriaBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/CriteriaBuilderImpl.java index a42492c1db..527d3e7183 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/CriteriaBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/CriteriaBuilderImpl.java @@ -587,12 +587,21 @@ public class CriteriaBuilderImpl implements HibernateCriteriaBuilder, Serializab @Override public ParameterExpression parameter(Class paramClass) { - return new ParameterExpressionImpl( this, paramClass, guessType( paramClass ) ); + return new ParameterExpressionImpl( + this, + paramClass, + sessionFactory.resolveParameterBindType( paramClass ) + ); } @Override public ParameterExpression parameter(Class paramClass, String name) { - return new ParameterExpressionImpl( this, paramClass, name, guessType( paramClass ) ); + return new ParameterExpressionImpl( + this, + paramClass, + name, + sessionFactory.resolveParameterBindType( paramClass ) + ); } @Override @@ -1352,27 +1361,4 @@ public class CriteriaBuilderImpl implements HibernateCriteriaBuilder, Serializab public > Predicate isNotMember(Expression eExpression, Expression cExpression) { return isMember(eExpression, cExpression).not(); } - - private Type guessType(Class clazz) throws HibernateException { - String typename = clazz.getName(); - Type type = sessionFactory.getTypeResolver().heuristicType( typename ); - boolean serializable = type != null && type instanceof SerializableType; - if ( type == null || serializable ) { - try { - sessionFactory.getMetamodel().entityPersister( clazz ); - } - catch ( MappingException me ) { - if ( serializable ) { - return type; - } - else { - throw new HibernateException( "Could not determine a type for class: " + typename ); - } - } - return sessionFactory.getTypeHelper().entity( clazz ); - } - else { - return type; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java index 0f28206570..2b7b088762 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java @@ -533,34 +533,11 @@ public abstract class AbstractProducedQuery implements QueryImplementor { type = parameterMetadata.getQueryParameter( namedParam ).getType(); } if ( type == null ) { - type = guessType( retType ); + type = getProducer().getFactory().resolveParameterBindType( retType ); } return type; } - private Type guessType(Class clazz) throws HibernateException { - String typename = clazz.getName(); - Type type = getProducer().getFactory().getTypeResolver().heuristicType( typename ); - boolean serializable = type != null && type instanceof SerializableType; - if ( type == null || serializable ) { - try { - getProducer().getFactory().getMetamodel().entityPersister( clazz ); - } - catch ( MappingException me ) { - if ( serializable ) { - return type; - } - else { - throw new HibernateException( "Could not determine a type for class: " + typename ); - } - } - return ( (Session) getProducer() ).getTypeHelper().entity( clazz ); - } - else { - return type; - } - } - @Override @SuppressWarnings("unchecked") public QueryImplementor setProperties(Map map) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java index b08eb7a39c..5b4167720e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java @@ -16,4 +16,5 @@ import org.hibernate.type.Type; */ public interface QueryParameterBindingTypeResolver { Type resolveParameterBindType(Object bindValue); + Type resolveParameterBindType(Class clazz); }