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..