From 756b42ec6e9e7fcc186e3c96f96b62809079bf82 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Fri, 10 Jan 2014 14:13:24 -0500 Subject: [PATCH] HHH-2188 Query metadata gives NPE for polymorphic queries --- .../hibernate/internal/SessionFactoryImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 cc58b8be20..ef691d4f25 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + import javax.naming.Reference; import javax.naming.StringRefAddr; @@ -104,6 +105,7 @@ import org.hibernate.engine.profile.Association; import org.hibernate.engine.profile.Fetch; import org.hibernate.engine.profile.FetchProfile; import org.hibernate.engine.query.spi.QueryPlanCache; +import org.hibernate.engine.query.spi.ReturnMetadata; import org.hibernate.engine.spi.CacheImplementor; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.Mapping; @@ -151,7 +153,6 @@ import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.AssociationType; import org.hibernate.type.Type; import org.hibernate.type.TypeResolver; - import org.jboss.logging.Logger; @@ -1195,15 +1196,15 @@ public final class SessionFactoryImpl } public Type[] getReturnTypes(String queryString) throws HibernateException { - return queryPlanCache.getHQLQueryPlan( queryString, false, Collections.EMPTY_MAP ) - .getReturnMetadata() - .getReturnTypes(); + final ReturnMetadata metadata = queryPlanCache.getHQLQueryPlan( queryString, false, Collections.EMPTY_MAP ) + .getReturnMetadata(); + return metadata == null ? null : metadata.getReturnTypes(); } public String[] getReturnAliases(String queryString) throws HibernateException { - return queryPlanCache.getHQLQueryPlan( queryString, false, Collections.EMPTY_MAP ) - .getReturnMetadata() - .getReturnAliases(); + final ReturnMetadata metadata = queryPlanCache.getHQLQueryPlan( queryString, false, Collections.EMPTY_MAP ) + .getReturnMetadata(); + return metadata == null ? null : metadata.getReturnAliases(); } public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {