Hello, i have little problem (searching forum for "one-to-one" didn't helped) and just want to be sure that im doing "right thing (tm)"....
I have two tables with 1 --> 0* relationship. Master table has generated ID and second table has ID assigned by "foreign" generator. Both entities are mapped to their counterparts by one-to-one mapping:
Code:
<class name="Cra.VubScoringEngine.BLL.FinancialStatement, Cra.VubScoringEngine.BLL" table="FinancialStatement">
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int"/>
<generator class="native" />
</id>
<one-to-one name="Score" class="Cra.VubScoringEngine.BLL.FinancialStatementScore, Cra.VubScoringEngine.BLL" cascade="all"/>
</class>
Code:
<class name="Cra.VubScoringEngine.BLL.FinancialStatementScore, Cra.VubScoringEngine.BLL" table="FinancialStatementScore">
<id name="Id" type="Int32" unsaved-value="0">
<column name="Id" sql-type="int" not-null="true" unique="true" index="PK_FinancialStatementScore"/>
<generator class="foreign">
<param name="property">FinancialStatement</param>
</generator>
</id>
<one-to-one name="FinancialStatement" class="Cra.VubScoringEngine.BLL.FinancialStatement, Cra.VubScoringEngine.BLL" constrained="true" >
</class>
Everything works just fine :)
BUT, now I want to find entities from FinancialStatement table with no corresponding entity in FinancialStatementScore table. So I run following query:
Code:
"SELECT fs FROM FinancialStatement as fs WHERE (fs.CisId = ?) AND (fs.Score is not null) ORDER BY fs.Year asc, fs.Type.Id asc"
But NHibernate creates SQL query which does not reference second table at all! "fs.Score is not null" is translated to "fs.Id is not null" (which is of course allways true). It seems like NHibernate is "too smart" here :))
I've found workaround by using this query:
Code:
"SELECT fs FROM FinancialStatement as fs WHERE (fs.CisId = ?) AND (fs.Score.ScoreValue is not null) ORDER BY fs.Year asc, fs.Type.Id asc"
But I am still currious :) Am I just using one-to-one mapping in the wrong way or is that bug ? Is there any better way to map ono-to-oneorzero relationships ?
Thanx for Your time !