-->
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: Map with composite foreign key
PostPosted: Wed Dec 14, 2005 12:32 pm 
Newbie

Joined: Wed Dec 14, 2005 12:01 pm
Posts: 2
hi,

i'm using Hibernate 3.1 (with Oracle 9i) and I have a question about mapping Maps.

I have an object called "SgBackendMapping" which has a Map field named "defaultAttributes". The keys and values are to be taken form the table "SG_DEFAULT_ATTRIBUTE". Entries of "SG_DEFAULT_ATTRIBUTE" reference "SgBackendMapping's" by a composite foreign key ( "BACKEND_ID" and "ORGANIZATION_ID" ) My problem is that I cannot specify a composite foreign key (as 'key') in the Map mapping.

I show in the following mapping file what I would like to do, but it is unfortunately not possible...

The Hibernate Reference Documentation 3.1 rc1 suggests that it was possible, but does not mention, how:

"Collection instances are distinguished in the database by the foreign key of the entity that owns the collection.
This foreign key is referred to as the collection key column (OR COLUMNS) of the collection table. The collection
key column is mapped by the <key> element."

any ideas? thank you!

Balazs

Code:
<hibernate-mapping package="com.baca.save.common.model.metadata">
   <class name="SgBackendMapping" lazy="false" table="SG_BACKEND_MAPPING">
   
       <composite-id>
           <key-many-to-one name="backend" class="SgBackend" >
              <column name="BACKEND_ID" />
          </key-many-to-one>
           <key-many-to-one name="organization" class="SgOrganization" >
              <column name="ORGANIZATION_ID" />
          </key-many-to-one>
       </composite-id>   

      <property name="status" column="STATUS" type="char" access="field"/>

      <!--
      <many-to-one name="backend" column="BACKEND_ID" class="SgBackend"/>      
      <many-to-one name="organization" column="ORGANIZATION_ID" class="SgOrganization"/>      
      -->

      <map name="defaultAttributes" lazy="true" table="SG_DEFAULT_ATTRIBUTE">
                           <!-- THIS IS INVALID!!!! -->
         <key>
            <column name="BACKEND_ID" />
            <column name="ORGANIZATION_ID" />
         </key>

         <key column="ORGANIZATION_ID"/>
         <index column="ATTR_NAME" type="string"/>
         <element type="string" column="ATTR_VALUE" not-null="true"/>
</map>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 12:44 pm 
Newbie

Joined: Wed Dec 14, 2005 12:01 pm
Posts: 2
sorry, there was an error, this is actually what I wanted:

Code:
<map name="defaultAttributes" lazy="true" table="SG_DEFAULT_ATTRIBUTE">
         <!-- THIS IS INVALID!!!! -->
         <key>
            <column name="BACKEND_ID" />
            <column name="ORGANIZATION_ID" />
         </key>

         <index column="ATTR_NAME" type="string"/>
         <element type="string" column="ATTR_VALUE" not-null="true"/>
</map>


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.