-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: One-to-one 'constrained='true' doesn't work for my mapping
PostPosted: Fri Jun 22, 2007 10:04 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
I'm having a select n+1 problem with a one-to-one mapping. And conflicting advice leaves me without a solution.

My one-to-one assocation is mapped exactly as per advice given in NHibernate In Action and the NHibernate documentation (see mapping files below).

But if I add the 'constrained=true' attribute to my one-to-one mapping, this error results:
Quote:
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'AccountID', table dbo.AccOther'; column does not allow nulls. INSERT fails.


I'm not yet quite sure what other parts of my current mapping (which works) I have to delete in order to get this new mapping concept to work.

My main 'Account' mapping:

Code:
<class name="Account" table="Accounts">
...
<one-to-one name="Other"
                    class="AccountOther"
                    property-ref="Account"
                    cascade="all" />
...


And my one-to-one AccountOther:
Code:
<class name="AccountOther" table="AccOther">
...
<many-to-one name="Account"
                     class="Account"
                     column="AccountID"
                     cascade="all"
                     unique="true" />
...


Last edited by PandaWood on Sat Jul 12, 2008 11:28 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 11:42 pm 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
The best solution to this, in my opinion, is to simply not use one-to-one mappings. You can easily map the same thing as a one-to-many and constrain your one-to-oneness in code. I did this and it fixed everything.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.