Custom JPA Build

It is well known that we can get an entity and all its children in a single JPQL query using the join fetch command. However, I cannot get this work to work with my own request. I get [Ljava.lang.Object; cannot be cast to com.myapp.SearchResult [Ljava.lang.Object; cannot be cast to com.myapp.SearchResult .

What happens is that I have a @SqlResultSetMapping configuration with multiple @EntityResult s. Some related entities are one-to-one. One of the relationships is a one-to-many relationship. Instead of a JPA that establishes a parent-child relationship, it returns one list of objects in a row, with each element in the list having one of the defined entity types.

Any idea how to make this work work as intended? Any examples of this case?

+4
source share
1 answer

You cannot join the selection in your own queries in the underlying JPA.

If you use EclipseLink, you can use the "eclipselink.join-fetch" Query tooltip to enable connection fetching in your own SQL query (without SqlResultSetMapping).

+3
source

Source: https://habr.com/ru/post/1369014/


All Articles