-->
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 problem
PostPosted: Fri Jun 06, 2008 2:07 am 
Newbie

Joined: Thu Jun 05, 2008 7:16 pm
Posts: 3
Hello All,

I have a many to one relationship between two object, which is working fine, except I wish to use a composite key, to match on but link on a single ID field. The reason I dont want to link on the composite key, is that I'll need ALL the fields of the second object included in the first object, which just so happens to be all of the fields in that object!

For example, Object A has this in its mapping file:

Code:
<many-to-one class="package.ObjectB" name="objectB" cascade="all" lazy="false" />


And Object B has:

Code:
        <composite-id>
            <key-property  column="data" name="data"/>
            <key-property  column="more_data" name="moreData"/>
            <key-property  column="even_more_data" name="evenMoreData"/>
        </composite-id>


Is there anyway I can have hibernate use a normal ID to link with (as in put that in the id field of the other table), but match records on the composite key?

I hope this make sense, and sorry if this has been asked before but Im unsure where to look for an answer.

Thanks,
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 11:34 pm 
Newbie

Joined: Thu Jun 05, 2008 7:16 pm
Posts: 3
Ok, so Ive found this bug, which has been fixed but not released:


http://opensource.atlassian.com/projects/hibernate/browse/HHH-2060

Ive applied the patch, and now I can do this in my class with the composite id:

Code:
<composite-id name="primaryId">
           
            <key-property column="a" name="a" type="string"  />
            <key-property column="b" name="b" type="string" />
            <key-property column="c" name="c" type="string" />
            <key-property column="d" name="d" type="string" />
            <key-property column="e" name="e" type="string" />
           
            <generator class="sequence">
                <param name="sequence">my_seq</param>
            </generator>
           
</composite-id>

<property column="primary_id" name="primaryId" type="integer" />


But NOW, when I try and use this via a many to one link such as:

Code:
    <many-to-one class="my.composite.Class"
    name="composite" cascade="all" lazy="false" property-ref="primaryId" column="primary_id" >


I get this error:

Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: component class not found: int
Exception in thread "Thread-1" java.lang.ExceptionInInitializerError
        at project.hibernate.HibernateDB.<clinit>(HibernateDB.java:59)


Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 6:20 pm 
Newbie

Joined: Thu Jun 05, 2008 7:16 pm
Posts: 3
so the only way of joining to a table with a composite key is via the composite key?? anybody? help!


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.