title: Hibernate code generation foreign keys reference objects
body: <p>I am using Hibernate reverse eng...
  I have a table User.
  I have table Recipe with Recipe_FK - to User.userId.</p>
  
  <p>When I run the code generation I get a POJO file for the user with:</p>
  
  <pre><code>private Set&lt;?&gt; recipeses = new HashSet&lt;Object&gt;(0);
  </code></pre>
  
  <p>Now - few questions:
  1. When I do session.load( User.class, userId );
  Will it do Join? and get the recipes from the Recipe table? I do not want that....
  Can I manually delete it?
  How can I reverse eng. the tables without getting this "Set" reference parameters?</p>
  
  <p>(I prefer to do the joins manually when needed to improve performances.)</p>
  
  <p>Here are the .hbm.xml files:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated Aug 26, 2011 10:56:44 AM by Hibernate Tools 3.4.0.CR1 --&gt;
  &lt;hibernate-mapping&gt;
   &lt;class catalog="yoavby2_icdb" name="com.icdb.data.Recipe" table="recipes"&gt;
    &lt;id name="recipeid" type="int"&gt;
     &lt;column name="recipeid"/&gt;
     &lt;generator class="identity"/&gt;
    &lt;/id&gt;
    &lt;many-to-one class="com.icdb.data.User" fetch="select" name="users"&gt;
     &lt;column name="ownerid" not-null="true"/&gt;
    &lt;/many-to-one&gt;
    &lt;property generated="never" lazy="false" name="releasedate" type="timestamp"&gt;
     &lt;column length="19" name="releasedate" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="preparationtime" type="int"&gt;
     &lt;column name="preparationtime" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="name" type="string"&gt;
     &lt;column length="50" name="name" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="description" type="string"&gt;
     &lt;column length="200" name="description"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="lastupdated" type="timestamp"&gt;
     &lt;column length="19" name="lastupdated" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="servecount" type="java.lang.Integer"&gt;
     &lt;column name="servecount"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="complete" type="boolean"&gt;
     &lt;column name="complete" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="ratingOneStar" type="int"&gt;
     &lt;column name="ratingOneStar" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="ratingTwoStar" type="int"&gt;
     &lt;column name="ratingTwoStar" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="ratingThreeStar" type="int"&gt;
     &lt;column name="ratingThreeStar" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="ratingFourStar" type="int"&gt;
     &lt;column name="ratingFourStar" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="ratingFiveStar" type="int"&gt;
     &lt;column name="ratingFiveStar" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="totalRating" type="float"&gt;
     &lt;column name="totalRating" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="category" type="int"&gt;
     &lt;column name="category" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="numOfViews" type="int"&gt;
     &lt;column name="numOfViews" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="indexOfRecipeOfUser" type="int"&gt;
     &lt;column name="indexOfRecipeOfUser" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="picUrl" type="string"&gt;
     &lt;column length="200" name="picUrl" not-null="false"/&gt;
    &lt;/property&gt;
    &lt;set fetch="select" inverse="true" lazy="true"
     name="recipeingredientses" sort="unsorted" table="recipeingredients"&gt;
     &lt;key&gt;
      &lt;column name="recipeid" not-null="true"/&gt;
     &lt;/key&gt;
     &lt;one-to-many class="com.icdb.data.RecipeIngredient"/&gt;
    &lt;/set&gt;
    &lt;set fetch="select" inverse="true" lazy="true" name="recipereviewses"
     sort="unsorted" table="recipereviews"&gt;
     &lt;key&gt;
      &lt;column name="recipeid" not-null="true"/&gt;
     &lt;/key&gt;
     &lt;one-to-many class="com.icdb.data.RecipeReviews"/&gt;
    &lt;/set&gt;
    &lt;set fetch="select" inverse="true" lazy="true"
     name="recipeinstructionses" sort="unsorted" table="recipeinstructions"&gt;
     &lt;key&gt;
      &lt;column name="recipeid" not-null="true"/&gt;
     &lt;/key&gt;
     &lt;one-to-many class="com.icdb.data.RecipeInstruction"/&gt;
    &lt;/set&gt;
    &lt;property name="recipedifficulty" type="int"&gt;
     &lt;column name="recipedifficulty" not-null="true" sql-type="INTEGER"/&gt;
    &lt;/property&gt;
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
  
  
  
  &lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 20:18:59 15/02/2012 by Hibernate Tools 3.4.0.CR1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="com.icdb.data.User" table="users" catalog="yoavby2_icdb"&gt;
          &lt;id name="userid" type="java.lang.Integer"&gt;
              &lt;column name="userid" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;property name="birthdate" type="string"&gt;
              &lt;column name="birthdate" length="50" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="password" type="string"&gt;
              &lt;column name="password" length="100" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="firstname" type="string"&gt;
              &lt;column name="firstname" length="50" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="lastname" type="string"&gt;
              &lt;column name="lastname" length="50" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="country" type="string"&gt;
              &lt;column name="country" length="100" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="email" type="string"&gt;
              &lt;column name="email" length="100" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="numOfRecipes" type="int"&gt;
              &lt;column name="numOfRecipes" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="picUrl" type="string"&gt;
              &lt;column name="picUrl" length="200" /&gt;
          &lt;/property&gt;
          &lt;set name="usermessagesesForSenderUserId" table="usermessages" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="senderUserId" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Usermessages" /&gt;
          &lt;/set&gt;
          &lt;set name="usermessagesesForUserId" table="usermessages" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="userId" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Usermessages" /&gt;
          &lt;/set&gt;
          &lt;set name="recipeses" table="recipes" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="ownerid" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Recipe" /&gt;
          &lt;/set&gt;
          &lt;set name="generaltipses" table="generaltips" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="authorid" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.GeneralTip" /&gt;
          &lt;/set&gt;
          &lt;set name="usersesForFavUserId" table="userfavchefsync" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="userId" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;many-to-many entity-name="com.icdb.data.User"&gt;
                  &lt;column name="favUserId" not-null="true" /&gt;
              &lt;/many-to-many&gt;
          &lt;/set&gt;
          &lt;set name="friendshiptablesForUserBId" table="friendshiptable" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="userB_Id" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Friendshiptable" /&gt;
          &lt;/set&gt;
          &lt;set name="usersesForUserId" table="userfavchefsync" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="favUserId" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;many-to-many entity-name="com.icdb.data.User"&gt;
                  &lt;column name="userId" not-null="true" /&gt;
              &lt;/many-to-many&gt;
          &lt;/set&gt;
          &lt;set name="friendshiptablesForUserAId" table="friendshiptable" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="userA_Id" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Friendshiptable" /&gt;
          &lt;/set&gt;
          &lt;set name="userrecipessyncs" table="userrecipessync" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="userId" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.Userrecipessync" /&gt;
          &lt;/set&gt;
          &lt;set name="recipereviewses" table="recipereviews" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="reviewerid" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="com.icdb.data.RecipeReviews" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Yoav</p>