OK, perhaps that is a bit confusing. So I'll rephrase the question:
I'd like to perform a left join where the join is not on an id column.
A simple example where this would be useful is a self-joined table used to
implement a tree:
Code:
PriceLevel Table (cost_level_id is a FK of the price_level_id)
price_level_id | cost_level_id | margin
This is used to represent various points in a supply chain, where one level's price is another level's cost, and every price has a cost. (or put differently, every item that will be sold must be bought first). Now consider a separate table used to represent prices (read-only):
Code:
Current Price Table
current_price_id | item_id| price_level_id| current_price
And one that represents potental prices (r/w):
Code:
Proposed Price Table
proposed_price_id | item_id | price_level_id | new_price | current_price
Finally, you'd like to create a set of proposed prices for given items at a given price_level, but the catch is, you'd like to populate the current price where it exists, and 0 or null for current price where it does not. This implies that you need proposed costs for the items as well as current prices.
This is straightforward using SQL, but I'm not sure how to do it in HQL, or if it is even possible (the previous linked thread says it is not).
So is there a way to create these objects from SQL, perform some business logic on them, and store them back through
Code:
session.save()
?
Or is it possible to use createSQLQuery to load the objects themselves?
(Item, PriceLevel, ProposedCost, CurrentPrice)?
Thanks for your help.