-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to fetch subobjects without getting duplicate rows?
PostPosted: Sat Oct 18, 2008 8:54 pm 
Newbie

Joined: Sat Oct 18, 2008 8:26 pm
Posts: 1
This should be a simple thing.

I have surveys. Each survey can have 0 to N attachments. I want to fetch all of my surveys, and all of their attachments. My object structure is that a Survey has a List of attachments.

I'm using Hibernate annotations. If I use fetchtype.EAGER, I get a duplicate row for every attachment a survey has. If I use fetchtype.LAZY, I get a runtime error because the session is closed when I go to access my attachments.

To summarize, if I have 5 surveys each with 3 attachments, I want 5 elements in my returned List, not 15. Is there a way to do this without having to filter the results through a LinkedHashSet first?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 1:00 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Apply a transformation to your Hibernate query, using

Code:
mycriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.