tags:

views:

60

answers:

3

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
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
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
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
My bad, I misinterpreted your question.
Lachlan Roche
+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