I have 2 tables viz. TABLE1 and TABLE2:
TABLE1 has it's PK as {ID}
TABLE2 has composite-id as {A,B,C}... TABLE2 also has a column {D}
TABLE1 and TABLE2 are associated with one-to-one mapping TABLE1.ID=TABLE2.A
Cascade-save is on.
Case1:Save()
I want TABLE1.ID=TABLE2.A and TABLE2.B='1' and TABLE2.C='2'
Case2:Get()
I want TABLE1.ID=TABLE2.A and TABLE2.B='1'and TABLE2.D='4'
How should i define this mapping?
Presently i have done like this :
Code:
<class name="Table1" table="TABLE1" optimistic-lock="version">
<id name="Id" column="ID">
<generator class="assigned" />
</id>
<one-to-one name="table2" class="Table2" cascade="save-update">
<formula>'1'</formula>
<formula>'2'</formula>
<formula>'3'</formula>
</one-to-one>
</class>
<class name="Table2" table="TABLE2" optimistic-lock="version">
<composite-id >
<key-property name="a" column="A" />
<key-property name="b" column="B" />
<key-property name="c" column="C" />
</composite-id>
<property name="d" column="D" />
<many-to-one name="table1" class="Table1" column="A" insert="false" update="false"/>
</class>
Save is working fine... but when it comes to Get(), the sql query is:
select *
from TABLE1 t1 left outer join TABLE2 t2 on '1'= t2.A and '2'=t2.B and '3'=t2.C where t1.ID=?
which is incorrect...