-->
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: Help with mapping to legacy db
PostPosted: Fri Mar 18, 2005 1:36 am 
Newbie

Joined: Wed Feb 11, 2004 9:31 pm
Posts: 2
Location: Adelaide, Australia
Hibernate #: 3 (any)

I have a rather unique situation where the database schema that I have to work with doesn't seem to be covered in any examples/doco. I hope I explain this well enough.

The sample schema that I have is as follows:

Code:
table code
(
  code char 4
  type  char 4
  data  varchar 100

  PRIMARY KEY(code,type)
)

table example
(
  data1 ...
  data2 ...
  code char 4
  ...
)


As you can see from the 'example' table, to get the data from the 'code' table you need both keys. In the legacy application this is done programatically in the sql:

Code:
select example.data1, code.data
from example, data
where example.code = code.code
and code.type = 'TYPE'


Is there anyway to do this in the hibernate mapping file (which would be the preferred way) as opposed to programatically. If anyone could help me out on this, it would be much appreciated.

_________________
Alex Rzemieniuk
Software Architect / Analyst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 2:30 am 
Beginner
Beginner

Joined: Sat Sep 25, 2004 12:42 am
Posts: 27
I don't think I really understand the relationships between the two tables from the details you have given, but, check out the "Components as composite identifiers" section of the hibernate documentation.

eg. The collection of OrderLines in Order would use:
Code:
<set name="orderLines" inverse="true">
    <key>
        <column name="orderId"/>
        <column name="customerId"/>
    </key>
    <one-to-many class="OrderLine"/>
</set>


Maybe you could include the mapping you have so far, or a simple ER diagram...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 2:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if looks like you need a combination of components and formula.

and if you look into formulajoin test in Hibernate 3 that *might* also help you.

_________________
Max
Don't forget to rate


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.