Joined: Mon Aug 18, 2008 10:54 am Posts: 11 Location: Devon, UK				
			 | 
			
				
				
					| 
					
						 I am having a problem with Hibernate not retrieving an inverse set.
  I am using NetBeans 6.8 with the Hibernate Framework 3.2.5 and have used NetBeans to generate all of my config and POJO's from my mysql database model. I am using the InnoDB engine in mysql to enforce Foreign Key relationships.
 
  I have three tables User, UserRoles and UserRole - 
  PK - Primary Key FK - Foreign Key
  User ----- ID (PK) Username Password
 
  UserRoles ----------- ID (PK) Username (FK -> User.Username) Role (FK -> UserRole.Role)
 
  UserRole ---------- Role Description
 
  I am issuing a Hibernate criteria query like this - 
  User u = (User)session.createCriteria(User.class).add(Restrictions.eq("username", username)).uniqueResult();
  This returns the User and their details correctly. However when I call u.getUserRoleses(), then the Set returned is always empty. I was under the impression that Hibernate should lazy evaluate and give me the data set when I request it?
  Is there some sort of problem with my mappings (below) or am I doing something wrong somehow?
  My hibernate mappings files look like this - 
  User.hbm.xml ---------------- <hibernate-mapping>     <class catalog="accountablecare" name="uk.co.accountablecare.web.orm.generated.User" table="User">         <id name="id" type="java.lang.Integer">             <column name="ID"/>             <generator class="identity"/>         </id>         <property name="username" type="string">             <column length="25" name="Username" not-null="true" unique="true"/>         </property>         <property name="password" type="string">             <column name="Password" not-null="true"/>         </property>         <set inverse="true" name="userRoleses">             <key>                 <column name="Username" not-null="true"/>             </key>             <one-to-many class="uk.co.accountablecare.web.orm.generated.UserRoles"/>         </set>     </class> </hibernate-mapping>
  UserRoles.hbm.xml ---------------------- <hibernate-mapping>   <class catalog="accountablecare" name="uk.co.accountablecare.web.orm.generated.UserRoles" table="UserRoles">     <id name="id" type="java.lang.Integer">       <column name="ID"/>       <generator class="identity"/>     </id>     <many-to-one class="uk.co.accountablecare.web.orm.generated.UserRole" fetch="select" name="userRole">       <column length="25" name="Role" not-null="true"/>     </many-to-one>     <many-to-one class="uk.co.accountablecare.web.orm.generated.User" fetch="select" name="user">       <column name="Username" not-null="true"/>     </many-to-one>   </class> </hibernate-mapping>
 
  UserRole.hbm.xml --------------------- <hibernate-mapping>   <class catalog="accountablecare" name="uk.co.accountablecare.web.orm.generated.UserRole" table="UserRole">     <id name="role" type="string">       <column length="25" name="Role"/>       <generator class="assigned"/>     </id>     <property name="description" type="string">       <column name="Description" not-null="true"/>     </property>     <set inverse="true" name="userRoleses">       <key>         <column length="25" name="Role" not-null="true"/>       </key>       <one-to-many class="uk.co.accountablecare.web.orm.generated.UserRoles"/>     </set>   </class> </hibernate-mapping>
 
  Thanks Adam. 
											 _________________ Adam Retter
					
  
						
					 | 
				 
				 
			 |