5

It's well known that we can retrieve an entity and all its children in a single JPQL query using join fetch. However, I can't seem to get this working with a native query. I'm getting [Ljava.lang.Object; cannot be cast to com.myapp.SearchResult.

What's happening is that I have an @SqlResultSetMapping configuration with multiple @EntityResults. Some related entities are one-to-one. One of the relationships is one-to-many. Instead of JPA setting up a parent-child relationship, it's returning one list of objects per row, with each item in the list being of one of the defined entity types.

Any idea how to get this working as intended? Any examples of this case?

1 Answer 1

3

You can't join fetch in native queries in basic JPA.

If you are using EclipseLink, you can use the "eclipselink.join-fetch" Query hint to enable a join fetch on a native SQL query (without an SqlResultSetMapping only).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.