-->
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: many-to-one with tricky keys
PostPosted: Thu Dec 02, 2004 3:15 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
Hibernate version: 2.1.7

hi,

i've got a many-to-one relation which i think is a little bit tricky and i haven't found a really satisfying solution so far ...

I've got two classes:
Code:
  public ClassA {
     Long id;
     ClassB cb;

     public void setCb(ClassB b) { this.cb = b; }
     public ClassB getClassB() { return this.cb; }
  }

   public ClassB {
     Long id;

     ....
  }


So no problem so far (a many-to-one mapping for that case is quite simple and working - therefore no mapping-files) ...

The problem starts when i'm trying to load ClassA.

Imagine the following tables:
Code:
  Table_ClassA
     id NUMERIC (pk)
     cb NUMERIC (fk to classB)
      ....

   Table_ClassB
      id NUMERIC (pk)
      code NUMERIC (pk) :(
      ....

   Table_A_Lot_of_Parameters
      ... somewhere in that table i'll find the currently right code to load ClassB ... :(


The steps to load ClassA must be the follwoing:
- determine the right code
- use a query to load ClassA

So far no problem, too ... in theory ;-)

my problem is, that the "many-to-one"-mapping in ClassA needs two column-definitions because ClassB has a composite-id ... but the required 'code' isn't persisted with ClassA ... therefore i'm not able to map this relation between ClassA and ClassB ... i could pass a constant value as 'code'-column, but that's not really what i want ...
Loading each Class on their own and setting ClassB to ClassA by hand is no problem, too but i would like to let hibernate do the work :)

But i'm standing on the line and have no idea how i could do that ... i'm pretty sure i've overlooked something or thinking to complex (confused ;) ) ...

could someone please push me into the right direction?

thanx!
curio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 10:46 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
no one has an idea? ...

the problem is that legacy-db-schema ... well okay ... if there's no way to handle it in an automatic way i will do that by hand ... not nice ... but okay.

gtx
curio


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.