views:

531

answers:

1

I'm doing some werid reporting from JPA datastore.

I need to select (using EJBQL) list of objects and these objects contain collection of entities ie I have class that is constructed by:

FOOBean(String param1, 
    String param2, 
    List<Entity> listParam)

(notice that third parapeter is a list)

And I want to select list of these bean using group by, fetching listParam along, so I would like to write query that works like:

      SELECT new FOOBean(
               e1.param1, 
               e1.param2,
               e1) 
               FROM Entity e1
               GROUP BY e1.param1, e1.param2

So grouped entities are fetched into list and inserted into third parameter. Is it possible to do it that way, or I have to create two queries - first that selects distinct pairs of param1 and param2, seconf that fethes all entoties with appropriate param values.

A: 

I think it would be much better to retrieve the object based on your condition & then use @oneToMany annotaion in your entity to set up the list.

Nayan Wadekar