-->
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: Force a lazily loaded field to load with hql
PostPosted: Thu Apr 28, 2011 3:01 pm 
Newbie

Joined: Thu Apr 28, 2011 2:47 pm
Posts: 1
Hi everybody

I have this strange behaviour when loading a collection of objects with hql.

Let's say I have a User table, a Channel table and a Post table.
A Post is contained inside a Channel. Each channel has various Post.
A Post has an author (User), and a Channel an owner (User) .

So, I'm trying to retrieve all the posts from a channel, with hql, in my Post DAO, it gives something like this:

Code:
hqlQuery.append("from Post as p");
hqlQuery.append(" left join fetch p.user");
hqlQuery.append(" where p.channel.idChannel = :id");


This is working great, except that all the Post which author is the same User as the Channel owner, seems to be lazily loaded, and the user.getFirstName() returns null.

In the debug, I have something like this for the field User :
Quote:
user User$$EnhancerByCGLIB$$85ff1fab (id=152)

This is for the case the author of the Post is the same as the owner of the Channel. For other users, I have "normal" Objects :
Quote:
user User (id=243)


So how can I kind of by-pass this lazy loading ? Or at least tell hibernate that it has to load the information it already retrieved from the Channel owner, since it seems to be what's happening.

Thanks in advance for your support, I'm quite new to hibernate and this is my first message on the board :)

Edit.: I think I'm mistaken somewhere, when running JUnit tests it seems to be working fine.. I'm using Spring OSIV and struts2, I'm not sure if it's related..


Top
 Profile  
 
 Post subject: Re: Force a lazily loaded field to load with hql
PostPosted: Sat Apr 30, 2011 11:59 pm 
Newbie

Joined: Sat Apr 30, 2011 11:55 pm
Posts: 1
well, thats really strange..

_________________
laser back surgery - laser spine - laser spine surgery


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.