dear guys,
I am using Hibernate 3.0.5, and there's many-to-many relation between Item and Tag object,
there's also one-to-many between Game and Tag.
the hibernate .hbm.xml fragment is as below:
Game.hbm.xml
<set name="tags" lazy="true" cascade="all" order-by="ITEM_INDEX asc">
<key column="GAME_ID"/>
<one-to-many class="com.domain.Tag" />
</set>
Item.hbm.xml
<set name="tags" lazy="true" table="ITEM_TAG">
<key column="ITEM_ID"/>
<many-to-many column="TAG_ID" class="com.domain.Tag" />
</set>
tag.hbm.xml
<property name="tagName" column="TAG_NAME" not-null="true" />
<property name="itemType" column="ITEM_TYPE" not-null="true" />
<property name="itemIndex" column="ITEM_INDEX" type="integer" not-null="false" />
<property name="gameId" column="GAME_ID" type="long" update="false" not-null="true" />
in the program, we add new tag to persistent game first, then add the tag to item.
nomally, it works well, the sql statement is below(we just add one new Item at one time):
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into tag (TAG_NAME, ITEM_TYPE, ITEM_INDEX, GAME_ID, TAG_ID) values (?, ?, ?, ?, ?)
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into ITEM (STATUS, GSC_ID, GSC_HOLDING_ID, ITEMNAME, ITEMTYPE, ITEMQTY, ITEMPROPERTY, bundle_id, OWNER_ID, SALELISTING_ID, BELONGED_GAME_ACCOUNT, TRANSFER_GAME_TARGET, BRIEFDESCRIPTION, LOCK_DATE, WITHDRAW_DATE, salable_type, ITEM_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'ITEM', ?)
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | update tag set GAME_ID=? where TAG_ID=?
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into ITEM_TAG (ITEM_ID, TAG_ID) values (?, ?)
sometimes the hibernate will generate the sql below(we add many new Items at one time):
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into ITEM (STATUS, GSC_ID, GSC_HOLDING_ID, ITEMNAME, ITEMTYPE, ITEMQTY, ITEMPROPERTY, bundle_id, OWNER_ID, SALELISTING_ID, BELONGED_GAME_ACCOUNT, TRANSFER_GAME_TARGET, BRIEFDESCRIPTION, LOCK_DATE, WITHDRAW_DATE, salable_type, ITEM_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'ITEM', ?)
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into tag (TAG_NAME, ITEM_TYPE, ITEM_INDEX, GAME_ID, TAG_ID) values (?, ?, ?, ?, ?)
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | insert into tag (TAG_NAME, ITEM_TYPE, ITEM_INDEX, GAME_ID, TAG_ID) values (?, ?, ?, ?, ?)
[LOGGER] 2007-04-25 09:47:06 DEBUG org.hibernate.SQL | update tag set GAME_ID=null where GAME_ID=? and TAG_ID=?
the last sql statement will trigger the database exception,because the constraint on gamd_id,and also this statement is wired.
any suggestions?
|