-->
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: fetching 'lazy loaded' collections
PostPosted: Fri Apr 13, 2007 12:19 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1
Mapping documents:

hi all,
i am experiencing huge problems in retrieving lazy-loaded collections with hibernate.....
quickly, i have following classes

Class A {
String field1
String field2
String field 3

List collection4
}

field4 is lazy loaded

i have an usecase where i have to retrieve field1, field2 and the collection (field 4)

i am writing the following query

Code:
select test.field1 as id
          test.field2 as f2 from  A as test
          join fetch test.collection4
          where test.field1 = :ABC "


hibernate3 complaints saying that

Code:
org.springframework.orm.hibernate3.HibernateQueryException: query specified join fetching, but the owner of the fetched association was not present in the select list


anyone could help me out?

thanks in advance and regards
marco


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 1:09 pm 
Beginner
Beginner

Joined: Thu Apr 12, 2007 3:26 am
Posts: 35
Location: Germany
I'am new to hibernate but I think that Hibernate warns you that it doesn't make sense to fetch the collection! You select only field1 and field2 so why should the collection be fetched? You will not be able to use it later. Hence, in my opinion, this exceptions warns you that you have a logical problem (Fetching of a collection although you won't use it later).

So you have to select the collection in one of the follwing ways:
Code:
select test.field1, test.field2, test.collection4 
from  A as test left join fetch test.collection4
where test.field1 = :ABC "


Code:
select test
from  A as test left join fetch test.collection4
where test.field1 = :ABC "


Hoeft


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.