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.Searc开发者_开发知识库hResult
.
What's happening is that I have an @SqlResultSetMapping
configuration with multiple @EntityResult
s. 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?
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).
精彩评论