How do I select a collection of objects and pass it to a bean as a parameter using EJBQL?

I am doing some strange posts from the JPA datastore.

I need to select (using EJBQL) a list of objects. These objects contain a collection of objects. I have a class that builds on:

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

      

(note that the third parameter is a list)

And I want to select a list of these beans using GROUP BY

, fetch listParam

, 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

      

Thus, the grouped objects are selected in the list and inserted into the third parameter. Is it possible to do this or do I need to create two queries that select separate pairs param1

and param2

; and selects all objects with corresponding parameter values ​​respectively?

+1


a source to share


2 answers


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



+1


a source


I think it would be much better to get an object based on your condition and then use @oneToMany annotaion on your entity to customize the list.



0


a source







All Articles