I have a User table which has a foreign key to the UserType table. I created a User object with a Type property that is mapped as a join to the UserType table. Is there a way to insert a new User without inserting a new UserType?
A:
I believe if the Type property is a new type that is not in the database (i.e. has no id yet) it will be inserted and given a new id. If the type was pulled out of the database, the user will be inserted and the id of the existing type will be used.
David Hogue
2010-01-18 01:33:15
Yeah, that was my thought too, but Nhibernate is not tracking Types because they are not entities... Do I have to have both a reference and a join so I can load the Type?
Robin Clowers
2010-01-18 01:37:40
A:
http://nhforge.org/doc/nh/en/index.html#mapping-declaration-join
Using the element, it is possible to map properties of one class to several tables, when there's a 1-to-1 relationship between the tables.
Meaning, each User will have a row in both tables.
Lachlan Roche
2010-01-18 01:42:13
I don't want to have a UserType entity at all, I am using <join> to include those columns in my User entity.
Robin Clowers
2010-01-18 01:55:37
+1
A:
This use of join is not supported, join is designed for 1 to 1 mappings. This was answered on the NH users list: http://groups.google.com/group/nhusers/browse_thread/thread/53ac080cb6512598.
Robin Clowers
2010-01-18 16:47:09