You can't join in HQL without mapping. The keyword "on" is native query and not recognized by HQL.
The example seems like you can just do a simple selection (select item.id from Item item or select stock.itemId from Stock stock). If you just simplified the example and you need all of the items even if there is no associated Stock I believe you can do this with a right outer join. This should give you all items from item and give you the "other" value from Stock in the cases where there is a match. This will give you a list of object arrays where the first element will be item.id and the second will be stock.other. The stock.other value will be null for items with no associate stock. (I added the "other" to the selection assuming you need something from stock, otherwise there is no reason to join, just select directly from Item.)
select distinct(item.id), stock.other from Stock stock right outer join stock.itemId
Just for the record, I am no expert but I hope this information helps.
|