-->
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: How to FK part of a composite-id PK
PostPosted: Sun Nov 30, 2003 4:13 pm 
Newbie

Joined: Sun Nov 30, 2003 4:11 pm
Posts: 11
Hi,

I've got a legacy database to deal with, and I'm almost getting crazy trying to make it work with Hibernate.

Let's say that there are 'n' Bs for each S, in a 1->n relationship.
In B, the FK (defined by tnumso field is also part of a composite-id PK.

Table S's PK mapping is like this:

<class
name="com.previsora.data.hibernate.S"
table="tatitul"
dynamic-update="false"
>
<id
name="numSolicitud"
column="tnumso"
type="long"
length="9"
unsaved-value="any"
>
<generator class="assigned">
</generator>
</id>
<set name="beneficiarios" >
<key>
<column name="tnumso"/>
</key>
<one-to-many class="com.previsora.data.hibernate.B"/>
</set>
[...]

My guess to table B mapping is:
<class
name="com.previsora.data.hibernate.B"
table="tabenef"
dynamic-update="false"
>
<composite-id name="PKBeneficiario" class="com.previsora.data.hibernate.BeneficiarioPK" unsaved-value="any">
<key-many-to-one name="numSolicitud" column="tnumso" inverse="true" />
<key-property name="numAsegurado" type="int" column="bnumer"/>
</composite-id>

But this will not work. "MappingException: No persister for long" All right, I think it means numSolicitud (which is a long indeed) but... what can I do? I've also tried:

<composite-id unsaved-value="any">
<key-property name="numSolicitud" type="long" column="tnumso"/>
<key-property name="numAsegurado" type="int" column="bnumer"/>
</composite-id>

But this does not make the many-to-one part of the relationship, and I need it.

Can anybody help me? BTW, I'm using Hibernate2.03, with mysql.

Lots of thanks,

_
Jorge


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2003 11:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
A <key-many-to-one> is supposed to map an object reference, just like an ordinary <many-to-one>. Alternatively you can map the column twice, once in the <composite-id>, and once with a <many-to-one insert="false" update="false"/>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 7:50 pm 
Newbie

Joined: Sun Nov 30, 2003 4:11 pm
Posts: 11
Thanks, Gavin.

As usual I was mixing two problems... I had tried with:

<composite-id name="PKBeneficiario" class="com.previsora.data.hibernate.BeneficiarioPK" unsaved-value="any">
<key-many-to-one name="Solicitud" class="com.previsora.data.hibernate.S" column="tnumso"/>
<key-property name="numAsegurado" type="int" column="bnumer"/>
</composite-id>

and it freezed... but then I discovered the cause of the freezing was my own faulty loopy code.

This works great, thanks!
I've got another problem, thought, but I think I will start another thread.

Thank you very much!

_
Jorge


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.