Instrumenting to enable lazy initialization of @Formula field, which is then added to an EntityGraph to force load for specific queries causes an error

Description

I have a field marked with...
@Basic(fetch = FetchType.LAZY)
@Formula("...")
...which works as it should. Adding that field to an EntityGraph for either fetch or load causes an error in the 'sort by' clause of my query which uses that field because the JPA query translator used by the EntityGraph seems unaware of the column, I assume because it's not part of the meta-model at that point. If I leave out the EntityGraph, everything is fine and the column is properly translated into its sql formula in the sort by clause. Further, if the field is accessed, it's acquired lazily properly. But if I attempt to turn off lazy loading for a particular query, to avoid N+1 lazy loading issues (and I either want the field or I will never touch it) using an EntityGraph with either fetch or load semantics, I get the error on query translation.

Environment

Hibernate 5.1.6, Java 8, MySql

Assignee

Unassigned

Reporter

David Berkman

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure