-->
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: One-to-many mapping with both tables having composite-id
PostPosted: Wed Feb 11, 2004 12:03 pm 
Newbie

Joined: Wed Feb 11, 2004 11:38 am
Posts: 2
Location: Paris, France
I am trying to solve the following issue :

Code:
create table B (
   businessKey NUMBER(19,0) not null,
   version NUMBER(10,0) not null,
   tbeg DATE not null,
   payload VARCHAR2(255),
   vbeg date,
   vend date,
   tend timestamp not null,
   status CHAR(1) not null,
   c_businessKey NUMBER(19,0),
   primary key (businessKey, version)
)

create table C (
   businessKey NUMBER(19,0) not null,
   version NUMBER(10,0) not null,
   tbeg DATE not null,
   payload VARCHAR2(255),
   vbeg date,
   vend date,
   tend timestamp not null,
   status CHAR(1) not null,
   primary key (businessKey, version)
)

where c_businessKey columns references C.businessKey.

The thing is C.businessKey is not unique.

What I would like to be able to do is to write a method on the object mapped to table B (let's call it BO) that would have a method getCByBusinessKey() that would return a list of CO where C.businessKey would be the one from B.c_businessKey.

I tried to map it as a list, but I does not work when I do the following for the mapping of B:
Code:
<list name="links" cascade="save-update">
  <key>
    <column name="c_businessKey"/>
  </key>
  <index column="version"/>
  <one-to-many class="com.bnpparibas.power.model.C"/>
</list>

The problem comes from the fact that CO has a composite-key so the list defined in BO must have both columns defined in the key.

What am I missing there?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can't do it with Hibernate.
map c_businessKey as a property and do a manual HQL resquest to get your list of C

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:26 pm 
Newbie

Joined: Wed Feb 11, 2004 11:38 am
Posts: 2
Location: Paris, France
emmanuel wrote:
You can't do it with Hibernate.
map c_businessKey as a property and do a manual HQL resquest to get your list of C

Quite a ugly hack :-)
I would like to separate my persistence model from Hibernate.

If I understand your solution, what your suggest is to alter BO so that it has a simple long property. Then if I want to provide a method List getCByBusinessKey() on BO, I'll have to write a HQL query within this method.

Is there any technical reason why Hibernate can't handle this case, or is it only because it is not *yet* implemented?

I was thinking about replacing the composite-ids with an simple id having two columns and using a custom UserType. If I do so, will the list mapping still be wrong?


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.