tags:

views:

101

answers:

3

When I retrieve a Parent-object, the Child-object's ID is not always predictable. For example, sometimes it is set with 0 (zero), sometimes the actual value and sometimes -1.

Why?

How can I solve this problem?

For code and mapping-files plz see this older question from me.

A: 

Your Teacher and TeacherDetail are setup different.

One is a many-to-one and the other is a one-to-one.

bleevo
+1  A: 

Considering that SQL Server's default identity setting will never set a value of 0 or -1 something is fishy.

Also, since the TeacherDetail is actually a supplementary/sibbling entity of Teacher why the additional ID for TeacherDetail? You can map a Primary Foreign Key in nhibernate

Jaguar
A: 

I would say that your premise is incorrect.

A single teacher only has a single detail, and therefore nothing is many-to-one. It's all just a property, as in a teacher has a property of TeacherDetail.

Either way, there is no way that TeacherDetailsMapping has a many-to-one...two teachers will never share the same details.

Fix the improper mapping and your issue, a result of bad mapping, will disappear.

The Mirage
I don't know whether you are aware or not, one-to-one relationship from the patent side is mapped as many-to-one with unique set to true. See this: http://nhforge.org/wikis/howtonh/lazy-loaded-one-to-one-with-nhibernate.aspx
JMSA
perhaps being clear about what you are trying to do would be helpful. That is a workaround 'trick' not a standard practice.Not sure what to tell you, I'm pretty sure you can map it "better".
The Mirage
@Mirage this IS the way to map one-to-ones; one side maps as a many-to-one
Jaguar