Use javax.persistence.Query#unwrap to implement addNamedQuery, rather than direct type checking

Description

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.

Initial report:


Adding a named query at runtime:

Results in:

Example app (commit): https://github.com/lincolnthree/con4456-coding-ee-7-easy-easier/commit/9749b9e94f51a3c3bbdca144ed5c5637cc854f1a

Environment

Wildfly AS

Status

Assignee

Steve Ebersole

Reporter

Lincoln Baxter, III

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure