2 Foreign Keys to the same Entity, but different Column Names, Bug?

16 views
Skip to first unread message

Greg

unread,
Feb 10, 2012, 4:53:42 AM2/10/12
to fluent-n...@googlegroups.com
My data structure:

Project {
    int id,
    User user,
    User owner,
    List<Notes> notes
}

User {
    int id, 
    string name
}

My issue is related around the Project-User relationship(s). When I map my Project I have 2 this:

References<User>(x => x.user).Column("user_id").ForeignKey();
References<User>(x => x.owner).Column("owner_id").ForeignKey();
This works a treat when adding and retrieving data to and from the database. I get 2 columns on the Project table that related to the correct instances of User.

However this is where it gets a little weird. When I delete a User, NHibernate will first select any Projects that have the user_id of the User.Id being deleted, update them to NULL and then delete the User. That's fine. But when I delete a User whose ID is stored in the owner_id column NHibernate doesn't seem to recognise that that column value need to be NULL'd before the User is removed. This causes a FK Ref exception.

Is there something I am missing from my mapping or organisation of data? Or is this simply a bug or just not possible?

Thanks,
Greg
Reply all
Reply to author
Forward
0 new messages