I have a table with several foreign keys. These foreign keys refer to enumeration tables. I need to get properties from these enumeration tables. I tried using the <join> mapping, but as far as I understand it, <join> assumes the enumeration tables have foreign keys to the mapped table, not mapped table with foreign keys to enumeration tables. Here is an example based on the mapping file below:
The GLAccountMap table has a foreign key (GLDebitAccountID) to GLDebitAccounts table (an enumeration). The GLDebitAccounts table has a value I want to use as a property in the AccountMap class (mapped to the GLAccountMap table).
How can I accomplish this? The documentation of <join> led me to the below mapping, but the generated SQL joins GLAccountMap.ID = GLDebitAccounts.ID, when really I want the join on GLAccountMap.GLDebitAccountID = GLDebitAccounts.ID. Is there a way to tell the <join> to do this join?
Hibernate version: 3.0.5
Mapping documents:
Code:
<hibernate-mapping package="com.ca.gl">
<class name="AccountMap" table="GLAccountMap">
<id name="id" column="ID">
<generator class="identity"/>
</id>
<many-to-one name="field" column="GLFieldID" class="Field" />
<!--<many-to-one name="account" column="AccountID" class="com.ca.buslib.acct.AbstractAccount" />-->
<join table="GLDebitAccounts">
<key column="ID"/>
<property name="debitGLAccount" column="Value"/>
</join>
<join table="GLCreditAccounts">
<key column="ID"/>
<property name="creditGLAccount" column="Value"/>
</join>
</class>
</hibernate-mapping>
Generated SQL: Code:
select
accountmap0_.ID as ID,
accountmap0_.GLFieldID as GLFieldID9_,
accountmap0_1_.Value as Value10_,
accountmap0_2_.Value as Value11_
from GLAccountMap accountmap0_
inner join GLDebitAccounts accountmap0_1_ on accountmap0_.ID=accountmap0_1_.ID
inner join GLCreditAccounts accountmap0_2_ on accountmap0_.ID=accountmap0_2_.ID
where accountId=352
Name and version of the database you are using: SQL Server 2000