I would like to be able to swap my JPA implementation between EclipseLink & Hibernate with a simple property change. I can do this ok but what is causing me problems is the named query validation. Using EclipseLink I have to write fetch joins like so:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index
JOIN id.index i
JOIN FETCH i.indexVersions
But when validating this query using Hibernate I get the following exception:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
So I can change the query to be HQL friendly like so:
SELECT id
FROM IndexDefinition id
JOIN FETCH id.index i
JOIN FETCH i.indexVersions
But this then causes the following exception in EclipseLink:
Exception Description Syntax error parsing the query [IndexDefinition.getForIndex] SELECT id FROM IndexDefinition id JOIN FETCH id.index i, syntax error at [id].
Internal Exception MismatchedTokenException(78!=-1)
I know I can use query hints at my DAO level to perform a fetch join but is there a way of pleasing both JPA implementations with a specific fetch join syntax?