These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Clarification on <join>
PostPosted: Wed Oct 12, 2005 11:10 am 
Newbie

Joined: Wed Aug 31, 2005 1:20 pm
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 11:04 pm 
Newbie

Joined: Wed Oct 19, 2005 10:09 pm
Posts: 1
I have the exact same problem. The way Hib does a join is backwards (imho).

I have

plan{planid, etc}
1 - many
planFeatures{planFeatureId, planId, featureId, other info}
many - 1
features{featureId, FeatureName, featureDesc, etc}

I wanted to join planFeature on feature. Then I could map plan to get a planFeature, which had all the feature info. But Hib is forcing the join to be in feature.

I hope there is a way around this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.