-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping joined tables in legacy database with SQL.
PostPosted: Fri Oct 05, 2007 2:51 pm 
Newbie

Joined: Tue May 01, 2007 10:20 am
Posts: 9
Hi All. I'm using NHibernate 1.2, though don't have problems going to trunk if necessary.

I've posted this problem before, thought I'd try again.

I have the following structure with composite keys in a legacy database

Code:
Table: Text
*KEY* ID
*KEY* Rev
*KEY* Sequence
TextLinesID
TextLinesRev

Table: TextLines:
*KEY* ID
*KEY* Rev
*KEY* Sequence
Data


Ignore the Key for Text, as that has nothing to do this at all, and does not pertain to the TextLines keys.

Each Text has a list of Data, which is found by looking at the TextLineID and TextLineRev columns, and getting all the rows in TextLines with that ID and Rev. The results are ordered by the Sequence column in the TextInstructionData table. Here is a sql statement to return all the rows of data for a Text with ID 65 rev 1.

SELECT TextLines.* FROM TextLines
LEFT JOIN Text ON Text.TextLinesID = TextLines.ID AND Text.TextLinesRev = TextLines.Rev
WHERE Text.ID = 65 AND Text.Revision = 1
ORDER BY TextLines.Sequence

I've successfully taken the above query and turned it into a named query, and was wondering, if there isn't a good way to map this relationship using the typical means, if I can take that query I made and use it by join fetching, such as seen in 16.4

Thanks for any help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.