Question

I'm doing some weird reporting from a JPA data store.

I need to select (using EJBQL) a list of objects. These objects contain collection of entities. I have a class that is constructed by:

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

(notice that third parameter is a list)

And I want to select a list of these beans using GROUP BY, fetching listParam along, so I would like to write a query that works like this:

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

So that grouped entities are fetched into a list and inserted into the third parameter. Is it possible to do it that way or do I have to create two queries that selects distinct pairs of param1 and param2; and fetches all entities with appropriate param values respectively?

Was it helpful?

Solution

It is not possible, at least in JPA 1.0 (and I doubt that in JPA 2.0 it is different).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top