Hi all,
I'm new to hql and I'm wondering if there is a straight way to select CollectionElement using the query language:
Given the model
Code:
public class UserDetails {
@Id
@GeneratedValue
private int id;
private String name;
@ElementCollection(fetch=FetchType.EAGER)
private List<String> phoneNumber = new ArrayList<String>();
[...]
}
I tried to fetch the name and the collection of phones with the following snippet:
Code:
Query query = session.createQuery("select ud.id,elements(ud.phoneNumber) from UserDetails ud where user='user 6'");
List<Object[]> listOfPro = (List<Object[]>) query.list();
for (Object[] o : listOfPro){
System.out.println(Arrays.asList(o));
}
But it yields a diffent array for every association userid - phone...
Is there a way to group the phones by the userid as by the original association?
Best regards