Fix guessType() method refactoring
This commit is contained in:
parent
3839fc8c8b
commit
4f72bd0cef
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -587,12 +587,21 @@ public class CriteriaBuilderImpl implements HibernateCriteriaBuilder, Serializab
|
|||
|
||||
@Override
|
||||
public <T> ParameterExpression<T> parameter(Class<T> paramClass) {
|
||||
return new ParameterExpressionImpl<T>( this, paramClass, guessType( paramClass ) );
|
||||
return new ParameterExpressionImpl<T>(
|
||||
this,
|
||||
paramClass,
|
||||
sessionFactory.resolveParameterBindType( paramClass )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ParameterExpression<T> parameter(Class<T> paramClass, String name) {
|
||||
return new ParameterExpressionImpl<T>( this, paramClass, name, guessType( paramClass ) );
|
||||
return new ParameterExpressionImpl<T>(
|
||||
this,
|
||||
paramClass,
|
||||
name,
|
||||
sessionFactory.resolveParameterBindType( paramClass )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1352,27 +1361,4 @@ public class CriteriaBuilderImpl implements HibernateCriteriaBuilder, Serializab
|
|||
public <E, C extends Collection<E>> Predicate isNotMember(Expression<E> eExpression, Expression<C> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -533,34 +533,11 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
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) {
|
||||
|
|
|
@ -16,4 +16,5 @@ import org.hibernate.type.Type;
|
|||
*/
|
||||
public interface QueryParameterBindingTypeResolver {
|
||||
Type resolveParameterBindType(Object bindValue);
|
||||
Type resolveParameterBindType(Class clazz);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue