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