JPA: Query that returns multiple entities

Viewed 90830

I'm writing a JPQL query that joins across three tables. In my resultlist I would like to get all three entities per matching row (hope that makes sense).

Any ideas?

Hibernate 3.x is my JPA provider.

4 Answers

In case of many to one or one to many relationship how to get multiple records of one of the entities? lets say A is one entity and B is another entity but they have one to many relationship and when you get result you expect B has one record and A has more than 1 record? My query is as below but I don't know how shall I get multiple records of 2nd entity?

@Query("SELECT wl, gr FROM WatchList as wl, GeozoneReference gr " +
            "WHERE wl.watchlistId = gr.objWatchList.watchlistId " +
            "AND wl.watchlistId =:watchlistId")
    List<Object[]> findWatchlistByWatchlistId(@Param("watchlistId") Long watchlistId);
Related