I have a relatioship that in the db (oracle9) is a one-to-many, but in the domain layer needs to be one-to-one. We have counties and populations, a county can have multiple population based on the source, but the application I'm working on, only uses one of the sources.
Here's the my initial mapping:
Code:
<class name="CountySurvey" table="MKT_SEG_SMPL_GEO">
<jcs-cache usage="read-only"/>
<id name="id" type="long" column="MKT_SEG_SMPL_GEO_GNMBR">
<generator class="assigned"/>
</id>
<many-to-one name="county" class="County" column="SG_SMPL_GEO_GNMBR"/>
<many-to-one name="marketSegment" class="MarketSegment" column="MS_MKT_SEG_GNMBR"/>
<one-to-one name="population" class="Population" foreign-key="MS_MKT_SEG_GNMBR"/>
</class>
<class name="Population" table="POPULATION" where="CDCH_CMPND_CHRSTC_GNMBR = 42 and PS_POP_SRC_GNMBR = 113">
<jcs-cache usage="read-only"/>
<id name="id" type="long" column="POP_GNMBR">
<generator class="assigned"/>
</id>
<property name="value" column="POP_VALUE"/>
</class>
As you can see the Populations class has a where clause with two predicates, that creates the one-to-one situation. When I run a list() on the population class by itself, the class level where clause is part of the query, but when the populations are retrieved as part of the relationship, the where clause is ignored.
Thanks for any help.