Skip to content

Commit bcfaebb

Browse files
committed
Merge pull request hibernate#11 from Naros/steve_HHH-10664_querySetPropertiesFix
FIx setProperties functionality.
2 parents 89068ea + d477216 commit bcfaebb

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
import org.hibernate.HibernateException;
3030
import org.hibernate.LockMode;
3131
import org.hibernate.LockOptions;
32+
import org.hibernate.MappingException;
3233
import org.hibernate.NonUniqueResultException;
3334
import org.hibernate.PropertyNotFoundException;
3435
import org.hibernate.ScrollMode;
3536
import org.hibernate.ScrollableResults;
37+
import org.hibernate.Session;
3638
import org.hibernate.TypeMismatchException;
3739
import org.hibernate.engine.query.spi.EntityGraphQueryHint;
3840
import org.hibernate.engine.query.spi.HQLQueryPlan;
@@ -54,11 +56,13 @@
5456
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
5557
import org.hibernate.property.access.spi.Getter;
5658
import org.hibernate.property.access.spi.PropertyAccess;
59+
import org.hibernate.proxy.HibernateProxyHelper;
5760
import org.hibernate.query.ParameterMetadata;
5861
import org.hibernate.query.QueryParameter;
5962
import org.hibernate.query.spi.QueryImplementor;
6063
import org.hibernate.query.spi.QueryParameterBinding;
6164
import org.hibernate.transform.ResultTransformer;
65+
import org.hibernate.type.SerializableType;
6266
import org.hibernate.type.StandardBasicTypes;
6367
import org.hibernate.type.Type;
6468

@@ -531,11 +535,33 @@ protected Type determineType(String namedParam, Class retType) {
531535
type = parameterMetadata.getQueryParameter( namedParam ).getType();
532536
}
533537
if ( type == null ) {
534-
type = StandardBasicTypes.SERIALIZABLE;
538+
type = guessType( retType );
535539
}
536540
return type;
537541
}
538542

543+
private Type guessType(Class clazz) throws HibernateException {
544+
String typename = clazz.getName();
545+
Type type = getProducer().getFactory().getTypeResolver().heuristicType( typename );
546+
boolean serializable = type != null && type instanceof SerializableType;
547+
if ( type == null || serializable ) {
548+
try {
549+
getProducer().getFactory().getMetamodel().entityPersister( clazz );
550+
}
551+
catch ( MappingException me ) {
552+
if ( serializable ) {
553+
return type;
554+
}
555+
else {
556+
throw new HibernateException( "Could not determine a type for class: " + typename );
557+
}
558+
}
559+
return ( (Session) getProducer() ).getTypeHelper().entity( clazz );
560+
}
561+
else {
562+
return type;
563+
}
564+
}
539565

540566
@Override
541567
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)