-->
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: left join fetch not returning any data
PostPosted: Wed Mar 08, 2006 1:12 pm 
Newbie

Joined: Fri Feb 10, 2006 7:19 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0
Mapping documents:
<hibernate-mapping>
<class name="com.serena.dashboard.security.users.User" table="USERS">
<id name="id" column="ID" />
<property name="userName" column="USER_NAME" />
<property name="fullName" column="FULL_USER_NAME"/>
<set name="groups" fetch="join" lazy="false">
<key column="MEMBER_USER_NAME_KEY"/>
<one-to-many class="com.serena.dashboard.security.users.Group" not-found="ignore" />
</set>

<property name="email" column="EMAIL_ADDR"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String hqlStatement = "select user from User user " +
"left join fetch user.groups group2 " +
"where group2.groupName like ? " +
"and user.userName like ? " +
"and user.fullName like ? " +
"and user.email like ? " +
"order by user.userName asc ";
Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
Hibernate: select * from ( select user0_.ID as ID0_, user0_.USER_NAME as USER2_0
_, user0_.FULL_USER_NAME as FULL3_0_, user0_.EMAIL_ADDR as EMAIL4_0_ from USERS
user0_ left outer join GROUPS groups1_ on user0_.ID=groups1_.MEMBER_USER_NAME_KE
Y where (groups1_.GROUP_NAME like ?) and (user0_.USER_NAME like ?) and (user0_.F
ULL_USER_NAME like ?) and (user0_.EMAIL_ADDR like ?) order by user0_.USER_NAME a
sc ) where rownum <= ?
Debug level Hibernate log excerpt:

I am trying to get all groups the user is member of in a set. As you can see I am using 'left join' and 'fetch' in my HQL query, but if user does not have any group assigned, I do not get any result back. I still want to get that user with 'no' group in the set. What am I doing wrong.

When there is a group, I get second SQL query immediately after the first one to get information about group. I don't see that query if group is not assigned.

- Meghana


Top
 Profile  
 
 Post subject: or
PostPosted: Wed Mar 08, 2006 1:44 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Well, it returns exactly what asked for: group2.groupName like ? AND rest of the criteria be satisfied.

I guess you need ( group2.groupName like ? OR group2 is null ) AND rest of criteria

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.