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