Trying to set up a joining of two tables. Using Hibernate 3.1.2 with the following signature:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
I have a Hibernate mapping against a database table which is working. However I have another table which contains extra information. I've tried a join in the mapping file but somehow it fails.
Lets call them Table1 og Table2.
Table1 has an attribute TAB1_Var_ID(not a primary key) and not defined as foreign key either(its an performance issue)
Table2 has a primary key TAB2_Var_ID which is connected to the TAB1_Var_ID
There is a many-to-one relationship.
Table1 can contain many TAB2_Var_ID
I am fairly new with Hibernate and don't have a clue what the cause of my problem is. Heres is my join mapping(with pseudonyms)
Code:
<hibernate-mapping>
<class name="SomeChildClass" table="Table1" lazy="false">
<composite-id>
<key-many-to-one..>
<key-property..>
<key-property..>
</composite-id>
...
<property name="varID" column="TAB1_Var_ID" type=integer" not-null="false"/>
<join table="Table2>
<key column="TAB1_Var_ID" property-ref="varID" unique="true"/>
<property name="someText" column="TAB2_SOME_TEXT" type="string" not-null="false"/>
</join>
</class>
</hibernate-mapping>
The variable someText and tab1VarID is in the SomeParentClass which SomeChildClass extends. SomeParentClass is not mapped.
The hibernate mapping is working without the join, but I need the someText value also in that mix.
I have tried reversing it with by mapping SomeParentClass and using <joined-subclass> with SomeChildClass, but I then get a syntax error on joined-subclass
Code:
<hibernate-mapping>
<class name="SomeParentClass" table="Table2" lazy="false">
<id name="varID" column="TAB2_Var_ID" type="integer"/>
<property name="someText" column="TAB2_SOME_TEXT" type="string" not-null="false"/>
<joined-subclass>
<composite-id>
<key-many-to-one..>
<key-property..>
<key-property..>
</composite-id>
...
<property name="varID" column="TAB1_Var_ID" type=integer" not-null="false"/>
</joined-subclass>
</class>
</hibernate-mapping>