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.  [ 4 posts ] 
Author Message
 Post subject: Mapping associations on alternate keys - property-ref
PostPosted: Wed Dec 02, 2009 10:58 am 
Newbie

Joined: Tue Sep 15, 2009 3:36 am
Posts: 7
Location: London
Hello,

I would like to use HQL to query and join two tables that don't have a 'proper' foreign key association. Is this possible?

So we basically have these 3 tables (distilled down to their essence).

Image

The Debtor and Item rows will be persisted separately and we purposely don't want a debtorId (way data is loaded we can't make the association at persist time) on the Item table (but I fear that is what the answer will be!).

In SQL I can perform the join easily on Item and Debtor to get Debtor names for Items (where they exist):

Image

But obviously I can't do this in HQL without providing a mapping of some kind. But I'm not sure how to map it - or if it is possible/advisable.

I have had a look around and am none the wiser about how to proceed so if anyone could point me in the correct direction it would be most appreciated.

Cheers

Mat


Top
 Profile  
 
 Post subject: Re: Mapping associations on alternate keys - property-ref
PostPosted: Sun Dec 06, 2009 7:24 am 
Newbie

Joined: Tue Sep 15, 2009 3:36 am
Posts: 7
Location: London
Kind of unsubtle bump...

Anyone any ideas - or is my post above so confused/ignorant that an answer is unlikely to ever appear?!

edit--hmmm looks like something similar has been asked before: viewtopic.php?t=971401&highlight=join+using+clause

So it would appear that left outer joins on unmapped tables aren't possible?


Top
 Profile  
 
 Post subject: Re: Mapping associations on alternate keys - property-ref
PostPosted: Sun Dec 06, 2009 3:24 pm 
Newbie

Joined: Wed Jul 30, 2008 1:03 am
Posts: 16
Not understanding the full picture, let me take a stab at it.

If you could get a Ledger object (which i believe has association with Debtor and Item?) then you could use that to get the necessary info:

Code:
from Ledger as l
  left join Debtor as d
  left join Item as i
where l.id = d.ledgerId and l.id = i.ledgerId

then get a list out of this HQL, and l.getDebtor().getName() and l.getItem().getAmount() should be what you wanted??

Ramin


Top
 Profile  
 
 Post subject: Re: Mapping associations on alternate keys - property-ref
PostPosted: Sun Dec 06, 2009 5:03 pm 
Newbie

Joined: Tue Sep 15, 2009 3:36 am
Posts: 7
Location: London
Ah yes, you did give me an idea - and this does seem to work. Performance will probably be woeful!

Code:
          from LedgerItem li
          join li.ledger l
          left join l.debtors d
          where li.debtorReference = d.reference


Cheers for the help.

Mat


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.