An app-server might wrap queries for various reasons. The initial report here actual came about because WildFly App Server does in fact wrap the javax.persistence.Query instances Hibernate produces in non-transactional cases.
Currently Hibernate does a direct type check to implement javax.persistence.EntityManagerFactory#addNamedQuery, checking that the incoming query is of type org.hibernate.jpa.HibernateQuery. This fails when WildFly has wrapped the query.
Same for the javax.persistence.StoredProcedureQuery branch inside #addNamedQuery too.
Adding a named query at runtime: