-->
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.  [ 3 posts ] 
Author Message
 Post subject: composite key class in a list
PostPosted: Thu Jun 01, 2006 3:56 pm 
Newbie

Joined: Thu Jun 01, 2006 2:47 pm
Posts: 1
hi,

i have searched a while for this but i still cant seem to grasp of how to get a list of objects which have a composite key defined.
I am working with good ole legacy(cannot modify db) and I need a way to manually assign the keys from the parent class.

I have the following working which gives me only one instance of an object:


Code:

<class name="org.Foo" table="Foo">
   
     <id name="id" column="db_object_id" unsaved-value="null">
    <generator class="assigned"/>
     </id>
    <property name="source_db"/>
    <property name="objectId"/>
    <property name="classificationId"/>

      <many-to-one name="objRight" class="org.ObjRight" insert="false"
       update="false">
           <column name="source_db" />
            <column name="ObjectID"   />
       </many-to-one>

      <many-to-one name="objClass" class="org.ObjClass" insert="false"
       update="false">
           <column name="source_db" />
            <column name="classificationId"   />
       </many-to-one>
</class>

objRight's composite key (source_db, objectId)
objClass's composite key (source_db, classificationId)



Now the above works like a charm, however, when i try to get a List of the above objects like so:

Code:

<list name="classfications" lazy="false" inverse="false"  cascade="none">
    <key>
            <column name="source_db"/>
            <column name="ObjectID"/>
      </key>
      <index column="db_object_id"/>
       <one-to-many class="org.ObjRight"/>
</list>    

<list name="rights" lazy="false" inverse="false"  cascade="none">
    <key>
            <column name="source_db"/>
            <column name="classificationID"/>
      </key>
      <index column="db_object_id"/>
       <one-to-many class="org.ObjClass"/>
</list>    



I get this exception:

org.hibernate.MappingException: Foreign key (ObjRight [source_db,ObjectID])) must have same number of columns as the referenced primary key (Foo [db_object_id])

i cannot make the parent class(Foo) have a composite key, since i need to provide different keys to different objects. Please Help!!

meeru


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 5:39 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Quote:
I need a way to manually assign the keys from the parent class.


Code:

<key-many-to-one
name="alsdfljf"
class="package.class"
>

<column name="primary_key" />
.....


</key-many-to-one>


_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 6:25 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
It's a little difficult to know what the exact problem is without the complete set of mappings. You should provide the mappings for the ObjRight and ObjClass entities. Also, you might want to fix the names of your lists in the mappings. You have the names reversed.

It looks like you might be missing a couple of things. Try this:

Code:
<list name="classfications" lazy="false" inverse="false"  cascade="none">
    <key>
            <column name="source_db"/>
            <column name="ObjectID"/>
    </key>
       <index column="db_object_id"/>
       <one-to-many class="org.ObjRight">
            <column name="source_db"/>
            <formula>objectId</formula>
       </one-to-many>
</list>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.