Saving entities with joins in the their mapping

12 views
Skip to first unread message

Robin Clowers

unread,
Jan 18, 2010, 10:27:35 AM1/18/10
to nhusers
Hi I originally posted this to stack overflow, but I didn't get an
answer quickly so I thought someone here might be able to help.

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?

http://stackoverflow.com/questions/2083415/how-do-you-save-an-nhibernate-entity-with-a-joined-field

Oskar Berggren

unread,
Jan 18, 2010, 10:47:19 AM1/18/10
to nhu...@googlegroups.com
You are either confused, or express yourself confusingly. :) You
don't provide technical details, but it sounds like you are using
<join> when in fact what you have is a one-to-many relationship. Map
this with <many-to-one> in the mapping for User.

The <join> element is when two or more tables should be used for the
_same_ object.

/Oskar


2010/1/18 Robin Clowers <robin....@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>
>
>
>

Robin Clowers

unread,
Jan 18, 2010, 11:03:24 AM1/18/10
to nhusers
Hi Oskar, thanks for your response. I'm not sure what technical
details you are looking for, but I will try and restate my question
more clearly.

I have a User table with a foreign key to a UserType table. I would
like to have a single entity, User which has the properties from both
tables. To do this, I am using the <join> element. I realize I would
map this a relationship, but that is not what I want.

Two questions, first: is this supported? I was able to load a user
with the join mapping, but have not been able to save one. Second: if
it is supported, is it a good idea?


On Jan 18, 7:47 am, Oskar Berggren <oskar.bergg...@gmail.com> wrote:
> You are either confused, or express yourself confusingly. :)   You
> don't provide technical details, but it sounds like you are using
> <join> when in fact what you have is a one-to-many relationship. Map
> this with <many-to-one> in the mapping for User.
>
> The <join> element is when two or more tables should be used for the
> _same_ object.
>
> /Oskar
>

> 2010/1/18 Robin Clowers <robin.clow...@gmail.com>:


>
>
>
> > Hi I originally posted this to stack overflow, but I didn't get an
> > answer quickly so I thought someone here might be able to help.
>
> > 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?
>

> >http://stackoverflow.com/questions/2083415/how-do-you-save-an-nhibern...

Oskar Berggren

unread,
Jan 18, 2010, 11:15:44 AM1/18/10
to nhu...@googlegroups.com
I believe you will not be able to do this with <join>. The element is
for when you have a 1-to-1 relationship.

Must the UserType be another table?

If you have a group of properties that can together be called
UserType, why do you believe it is a good idea to expose them as
properties directly on the User?

Obviously I don't know all the details but my gut feeling is that if
you want to categorize users, it sort of defeats the purpose if you
don't reflect this in you model by having a UserType entity.

/Oskar


2010/1/18 Robin Clowers <robin....@gmail.com>:

Robin Clowers

unread,
Jan 18, 2010, 11:45:21 AM1/18/10
to nhusers
I am just trying to understand the capabilities of NH, this is not a
for a real application (sorry I didn't mention this before).

Thanks for your help Oskar, I did not realize join was only for 1 to 1
relationships.


On Jan 18, 8:15 am, Oskar Berggren <oskar.bergg...@gmail.com> wrote:
> I believe you will not be able to do this with <join>. The element is
> for when you have a 1-to-1 relationship.
>
> Must the UserType be another table?
>
> If you have a group of properties that can together be called
> UserType, why do you believe it is a good idea to expose them as
> properties directly on the User?
>
> Obviously I don't know all the details but my gut feeling is that if
> you want to categorize users, it sort of defeats the purpose if you
> don't reflect this in you model by having a UserType entity.
>
> /Oskar
>

> 2010/1/18 Robin Clowers <robin.clow...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages