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 @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?