have a look on how map a bidi-one-to-one through PK http://fabiomaulo.blogspot.com/2010/03/conform-mapping-one-to-one.html
On Wed, Nov 17, 2010 at 1:38 PM, Scott <[email protected]> wrote: > I'm mapping bidirectional through the PK, so the PK of both tables are > the same. > > Like I said it works the first time and then failed to include the > where clause the 2nd, so if I was doing something horribly wrong I'd > think it should fail the first time. The fact that the 2nd query > include the correct parameters but never uses them sounds more like a > bug in NHibernate to me. > > > > On Nov 15, 6:21 pm, Fabio Maulo <[email protected]> wrote: > > There 3 mapping patterns to map a one-to-one. > > Just one for unidirectional relation > > Two for bidirectional (oen through PK the other through FK). > > > > Which is your case? > > > > -- > > Fabio Maulo > > > > El 15/11/2010, a las 16:25, Scott <[email protected]> escribió: > > > > > > > > > A little more I discovered after testing. > > > > > It doesn't matter if the Child is null, I added the records and it > > > still does the same thing. > > > > > And it only happens the 2nd time through, the first time everything is > > > fine, the 2nd time and the query is wrong doing the exact same thing. > > > > > On Nov 15, 10:51 am, Scott <[email protected]> wrote: > > >> I have a one-to-one relationship and when the child table is null for > > >> the main object the SQL query that's created is wrong, it gives it a > > >> parameter of the primary key but it never uses this parameter in the > > >> query itself. This causes it to return all records in the table and a > > >> "More than one row with the given identifier was found" error when > > >> actually it shouldn't be finding anything. > > > > >> Parent has: > > >> <one-to-one name="Profile" class="DatabaseModel.Models.UserProfile, > > >> DatabaseModel" cascade="all" property-ref="UserInfo" /> > > > > >> Child has: > > >> <one-to-one name="UserInfo" class="DatabaseModel.Models.UserInfo" > > >> cascade="delete" constrained="true" /> > > > > >> The query that gets generated is: > > >> exec sp_executesql N'SELECT userprofil0_.UserInfoRefId as > > >> UserInfo1_4_0_, userprofil0_.Version as Version4_0_, > > >> userprofil0_.CurrentRosmatRefId as CurrentR3_4_0_ FROM UserProfile > > >> userprofil0_',N'@p0 uniqueidentifier',@p0='60E9764B- > > >> D48E-4260-81BC-308B3486851F' > > > > >> Notice the lack of a WHERE clause > > > > >> This is what I think it should be: > > >> exec sp_executesql N'SELECT userprofil0_.UserInfoRefId as > > >> UserInfo1_4_0_, userprofil0_.Version as Version4_0_, > > >> userprofil0_.CurrentRosmatRefId as CurrentR3_4_0_ FROM UserProfile > > >> userprofil0_ WHERE userprofil0_.userinforef...@p0',N'@p0 > > >> uniqueidentifier',@p0='60E9764B-D48E-4260-81BC-308B3486851F' > > > > >> This is on NHibernate 2.1.2 > > > > > -- > > > You received this message because you are subscribed to the Google > Groups "nhusers" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > > > For more options, visit this group athttp:// > groups.google.com/group/nhusers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
