我使用Hibernate逆向工程...... 我有一個表的用戶。 我有食譜Recipe_FK - 到User.userId。Hibernate的代碼生成的外鍵引用對象
當我運行的代碼生成我得到了與用戶POJO文件:
private Set<?> recipeses = new HashSet<Object>(0);
現在 - 幾個問題:1。 當我做session.load(User.class,用戶id); 它會加入嗎?並從食譜表中獲取食譜?我不想那樣... 我可以手動刪除它嗎? 我怎樣才能扭轉英格蘭。沒有得到這個「設置」參考參數的表?
(我喜歡做需要提高性能時,手動連接。)
這裏是的.hbm.xml文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 26, 2011 10:56:44 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class catalog="yoavby2_icdb" name="com.icdb.data.Recipe" table="recipes">
<id name="recipeid" type="int">
<column name="recipeid"/>
<generator class="identity"/>
</id>
<many-to-one class="com.icdb.data.User" fetch="select" name="users">
<column name="ownerid" not-null="true"/>
</many-to-one>
<property generated="never" lazy="false" name="releasedate" type="timestamp">
<column length="19" name="releasedate" not-null="true"/>
</property>
<property generated="never" lazy="false" name="preparationtime" type="int">
<column name="preparationtime" not-null="true"/>
</property>
<property generated="never" lazy="false" name="name" type="string">
<column length="50" name="name" not-null="true"/>
</property>
<property generated="never" lazy="false" name="description" type="string">
<column length="200" name="description"/>
</property>
<property generated="never" lazy="false" name="lastupdated" type="timestamp">
<column length="19" name="lastupdated" not-null="true"/>
</property>
<property generated="never" lazy="false" name="servecount" type="java.lang.Integer">
<column name="servecount"/>
</property>
<property generated="never" lazy="false" name="complete" type="boolean">
<column name="complete" not-null="true"/>
</property>
<property generated="never" lazy="false" name="ratingOneStar" type="int">
<column name="ratingOneStar" not-null="true"/>
</property>
<property generated="never" lazy="false" name="ratingTwoStar" type="int">
<column name="ratingTwoStar" not-null="true"/>
</property>
<property generated="never" lazy="false" name="ratingThreeStar" type="int">
<column name="ratingThreeStar" not-null="true"/>
</property>
<property generated="never" lazy="false" name="ratingFourStar" type="int">
<column name="ratingFourStar" not-null="true"/>
</property>
<property generated="never" lazy="false" name="ratingFiveStar" type="int">
<column name="ratingFiveStar" not-null="true"/>
</property>
<property generated="never" lazy="false" name="totalRating" type="float">
<column name="totalRating" not-null="true"/>
</property>
<property generated="never" lazy="false" name="category" type="int">
<column name="category" not-null="true"/>
</property>
<property generated="never" lazy="false" name="numOfViews" type="int">
<column name="numOfViews" not-null="true"/>
</property>
<property generated="never" lazy="false" name="indexOfRecipeOfUser" type="int">
<column name="indexOfRecipeOfUser" not-null="true"/>
</property>
<property generated="never" lazy="false" name="picUrl" type="string">
<column length="200" name="picUrl" not-null="false"/>
</property>
<set fetch="select" inverse="true" lazy="true"
name="recipeingredientses" sort="unsorted" table="recipeingredients">
<key>
<column name="recipeid" not-null="true"/>
</key>
<one-to-many class="com.icdb.data.RecipeIngredient"/>
</set>
<set fetch="select" inverse="true" lazy="true" name="recipereviewses"
sort="unsorted" table="recipereviews">
<key>
<column name="recipeid" not-null="true"/>
</key>
<one-to-many class="com.icdb.data.RecipeReviews"/>
</set>
<set fetch="select" inverse="true" lazy="true"
name="recipeinstructionses" sort="unsorted" table="recipeinstructions">
<key>
<column name="recipeid" not-null="true"/>
</key>
<one-to-many class="com.icdb.data.RecipeInstruction"/>
</set>
<property name="recipedifficulty" type="int">
<column name="recipedifficulty" not-null="true" sql-type="INTEGER"/>
</property>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20:18:59 15/02/2012 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.icdb.data.User" table="users" catalog="yoavby2_icdb">
<id name="userid" type="java.lang.Integer">
<column name="userid" />
<generator class="identity" />
</id>
<property name="birthdate" type="string">
<column name="birthdate" length="50" not-null="true" />
</property>
<property name="password" type="string">
<column name="password" length="100" not-null="true" />
</property>
<property name="firstname" type="string">
<column name="firstname" length="50" not-null="true" />
</property>
<property name="lastname" type="string">
<column name="lastname" length="50" not-null="true" />
</property>
<property name="country" type="string">
<column name="country" length="100" not-null="true" />
</property>
<property name="email" type="string">
<column name="email" length="100" not-null="true" />
</property>
<property name="numOfRecipes" type="int">
<column name="numOfRecipes" not-null="true" />
</property>
<property name="picUrl" type="string">
<column name="picUrl" length="200" />
</property>
<set name="usermessagesesForSenderUserId" table="usermessages" inverse="true" lazy="true" fetch="select">
<key>
<column name="senderUserId" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Usermessages" />
</set>
<set name="usermessagesesForUserId" table="usermessages" inverse="true" lazy="true" fetch="select">
<key>
<column name="userId" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Usermessages" />
</set>
<set name="recipeses" table="recipes" inverse="true" lazy="true" fetch="select">
<key>
<column name="ownerid" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Recipe" />
</set>
<set name="generaltipses" table="generaltips" inverse="true" lazy="true" fetch="select">
<key>
<column name="authorid" not-null="true" />
</key>
<one-to-many class="com.icdb.data.GeneralTip" />
</set>
<set name="usersesForFavUserId" table="userfavchefsync" inverse="true" lazy="true" fetch="select">
<key>
<column name="userId" not-null="true" />
</key>
<many-to-many entity-name="com.icdb.data.User">
<column name="favUserId" not-null="true" />
</many-to-many>
</set>
<set name="friendshiptablesForUserBId" table="friendshiptable" inverse="true" lazy="true" fetch="select">
<key>
<column name="userB_Id" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Friendshiptable" />
</set>
<set name="usersesForUserId" table="userfavchefsync" inverse="true" lazy="true" fetch="select">
<key>
<column name="favUserId" not-null="true" />
</key>
<many-to-many entity-name="com.icdb.data.User">
<column name="userId" not-null="true" />
</many-to-many>
</set>
<set name="friendshiptablesForUserAId" table="friendshiptable" inverse="true" lazy="true" fetch="select">
<key>
<column name="userA_Id" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Friendshiptable" />
</set>
<set name="userrecipessyncs" table="userrecipessync" inverse="true" lazy="true" fetch="select">
<key>
<column name="userId" not-null="true" />
</key>
<one-to-many class="com.icdb.data.Userrecipessync" />
</set>
<set name="recipereviewses" table="recipereviews" inverse="true" lazy="true" fetch="select">
<key>
<column name="reviewerid" not-null="true" />
</key>
<one-to-many class="com.icdb.data.RecipeReviews" />
</set>
</class>
</hibernate-mapping>
約阿夫
請出示上標明的配方和用戶類兩個完整的註釋 – 2012-02-21 17:19:34
請參閱編輯您的幫助 – user1136875 2012-02-21 18:12:45