-->
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: one-to-many and composite-id on index column
PostPosted: Tue May 23, 2006 3:25 pm 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2

Suppose i've this schema (reduced for clear read):

create table `articles` (art_id INTEGER prymary key, art_data date)
create table `registrations` (art_id INTEGER, reg_id integer, reg_value NUMERIC, PRIMARY KEY(art_id, reg_id))

how can i map the primary key of the register?
I do:
Code:
On article:

<list name="registrazioni" table="registrations" cascade="all-delete-orphan" inverse="false">
   <key column name="art_id"/>
        <index column="reg_id"/>
   <one-to-many class="sic.business.Registrazione"/>
</list>

on registration:
<composite-id class="sic.business.Registrazione$Id" >
  <key-many-to-one name="article" class="sic.business.Articolo" column name="art_id">
  <key-property name="id" type="int" column="reg_id"/>
</composite-id>


but when i call session.persist(article)

i receive a exception that the registration have same id of anothewr registration i suppose because the "id" property is null and the hashCode of Registrazione.Id is the same.

in which way i can do this mapping? i had to add another field to registrations table?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 6:34 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
You don't need another field. You just need to set all parts of the primary key so that the combined values are unique for each row that you want to add to the table.


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.