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