diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java index 69e662a6fe..52ac30b809 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java @@ -401,7 +401,7 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { final HibernateQuery unwrapped = query.unwrap( HibernateQuery.class ); if ( unwrapped != null ) { // create and register the proper NamedQueryDefinition... - final org.hibernate.Query hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery(); + final org.hibernate.Query hibernateQuery = unwrapped.getHibernateQuery(); if ( org.hibernate.SQLQuery.class.isInstance( hibernateQuery ) ) { sessionFactory.registerNamedSQLQueryDefinition( name,