-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ElementCollection projection
PostPosted: Fri Apr 26, 2013 9:22 am 
Newbie

Joined: Fri Apr 26, 2013 9:06 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.