-->
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.  [ 3 posts ] 
Author Message
 Post subject: Populating Entity with selected collection fields only (JPA)
PostPosted: Thu Apr 09, 2009 3:47 am 
Newbie

Joined: Thu Apr 09, 2009 2:01 am
Posts: 2
Hibernate version: 3.2.4.sp1 with JPA

Hi,

Example entity contains fields:
Code:
class Example {
private long id;
private String name;
private List<OtherEntity> list1;
private List<OtherEntity> list2;
private List<AnotherEntity> list3;



I want to create query like this:
Code:
List<Example> list = entityManager.createQuery("Select e From Entity");


But I like to have only name, and list1 fields populated. What is the best way to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 4:44 am 
Newbie

Joined: Tue Feb 05, 2008 11:35 am
Posts: 10
An idea (maybe not working :)

- create a constructor
Code:
Example(String name, List<OtherEntity> list1)

- modify the query to something like
Code:
select new Example(e.name, list1) from Example e join e.list1 as list1


Note that the returned Example instances will not be persistent, so probably it is not a good strategy to use your entities like this, maybe it would be better to create custom javabeans!

--
Norbi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 16, 2009 1:06 am 
Newbie

Joined: Thu Apr 09, 2009 2:01 am
Posts: 2
snorbicet wrote:
An idea (maybe not working :)

- create a constructor
Code:
Example(String name, List<OtherEntity> list1)

- modify the query to something like
Code:
select new Example(e.name, list1) from Example e join e.list1 as list1


--
Norbi


Hi,

I tried that but without success. I think this is an important issue on cases where lots of data and lots of fields. Is there any means to do column filtering.


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

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.