heres my hbm examples for i am trying
TABLE1
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="Table1Model"
table="TABLE1"
>
<composite-id name="table1Key">
<key-property name="key1" type="java.lang.String" column="KEY1" />
<key-property name="key2" type="java.lang.String" column="KEY2" />
</composite-id>
<property name="col1" type="java.lang.String" column="COL1" />
<property name="col2" type="java.lang.Integer" column="COL2" />
<property name="col3" type="java.lang.String" column="COL3" />
<many-to-one
name="table2key"
class="Table2Model"
insert="false" update="false" not-null="false"
cascade="none"
>
<column name="COL1" />
<column name="COL2" />
<column name="COL3" />
</many-to-one>
</class>
</hibernate-mapping>
TABLE2
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="Table2Model"
table="TABLE2"
>
<composite-id name="table2key">
<key-property name="col1" type="java.lang.String" column="COL1" />
<key-property name="col2" type="java.lang.Integer" column="COL2" />
<key-property name="col3" type="java.lang.String" column name="COL3" />
</composite-id>
<property name="colY" type="java.lang.Integer">
<column name="COLY" sql-type="decimal(10,0)" />
</property>
<property name="colZ" type="java.lang.String">
<column name="COLZ" sql-type="char(6)" />
</property>
</class>
</hibernate-mapping>
the resulting SQL statement hibernate generates is:
Code:
select this.KEY1 as KEY1_, this.KEY2 as KEY21_, this.COL1 as COL1_, this.COL2 as COL2_, this.COL3 as COL3_, table2_.COLY as COLY_, table2_.COLZ as COLZ_, from TABLE1 this left outer join TABLE2 table2_
on this.COL1=table2_.COL1 and this.COL2=table2_.COL2 and this.COL3=table2_.COL3
which is exactly what i need, but if there is nothing for table2 then hibernate tries getting it with another query something like
Code:
select table2_.COL1 as COL1_, table2_.COL2 as COL2_, table2_.COL3 from TABLE2 table2_ where table2_.COL1=? and table2_.COL2=? and table2_.COL3=?
this generates a
No row with the given identifier exists error
i simply do not need the 2nd query. a null object for table2 is fine
thanks