-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: FOREIGN KEY constraint , when two subclass map to one table
PostPosted: Tue Sep 13, 2005 3:09 am 
Newbie

Joined: Tue Sep 13, 2005 2:18 am
Posts: 2
when two subclass map to one table, if there are other two classes, have one-to-many relation to both the two subclass. i got an error when add a subclass. the error is "INSERT statement conflicted with COLUMN FOREIGN KEY constraint FK53725E6FF1AECC7E57DFD82D'. The conflict occurred in database 'wunding', table 'game_module_instance', column 'module_instance_id'. "

the subclass map file like this

Code:
   <class
       name='PlayerState'
       table='game_player_state'>
      <id
          name='ID'
          type='integer'
          unsaved-value='0'>
         <generator
             class='native' />
      </id>
      <discriminator
          column='game_or_module'
          type='string' />
      <property
          name='PlayerID'
          type='integer'
          column='player_id'
          not-null='true' />
      <property
          name='InstanceID'
          type='integer'
          column='instance_id'
          not-null='true' />
      <subclass name="GamePlayerState" discriminator-value="Game" extends="PlayerState">
      </subclass>
      <subclass name="ModulePlayerState" discriminator-value="Module" extends="PlayerState">
      </subclass>
      
   </class>


GameInstanceEntity and ModuleInstanceEntity both have onlinePlayerList. Following is the map file.
Code:
   <class
       name='GameInstanceEntity'
       table='game_instance'>
      <id
          name='GameInstanceID'
          column='game_instance_id'
          type='integer'
          unsaved-value='0'>
         <generator
             class='native' />
      </id>
      <set
          name='OnlinePlayerList'
          table='game_player_state'
          lazy='true'>
         <key
             column='instance_id'  />
         <one-to-many
             class='wd_game1.DataAccess.GamePlayerState, wd_game1.DataAccess' />
            
      </set>
      <set
          name='OfflinePlayerList'
          table='game_player_state'
          lazy='true'>
         <key
             column='instance_id' />
         <one-to-many
             class='wd_game1.DataAccess.GamePlayerState, wd_game1.DataAccess' />
      </set>
   </class>



   <class
       name='ModuleInstanceEntity'
       table='game_module_instance'>
      <id
          name='ModuleInstanceID'
          column='module_instance_id'
          type='integer'
          unsaved-value='0'>
         <generator
             class='native' />
      </id>
      <many-to-one
          name='GameInstance'
          class='wd_game1.DataAccess.GameInstanceEntity'
          column='module_instance_id' />
      <set
          name='OnlinePlayerList'
          table='game_player_state'
          lazy='true'>
         <key
             column='instance_id' />
         <one-to-many
             class='wd_game1.DataAccess.ModulePlayerState, wd_game1.DataAccess'  />
      </set>
      <set
          name='OfflinePlayerList'
          table='game_player_state'
          lazy='true'>
         <key
             column='instance_id' />
         <one-to-many
             class='wd_game1.DataAccess.ModulePlayerState, wd_game1.DataAccess' />
      </set>
   </class>



when i add a playState object, the error occours
Code:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint FK53725E6FF1AECC7E57DFD82D'. The conflict occurred in database 'wunding', table 'game_module_instance', column 'module_instance_id'. 


if i remove the constraint manual with SQLServer Enterprise Manger, no error occour, and the recordset will be inserted.

How can i deal with this problem. Am i do a bad design?

I am new to nhibernate, thx to your replay.
MSN: sz2080@hotmail.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.