-->
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: Translate simple SQL query to HQL
PostPosted: Mon Sep 22, 2008 6:45 am 
Newbie

Joined: Wed Jun 06, 2007 2:03 am
Posts: 2
I have 3 entities:
Code:
public class Item
{
  public Long id;
}

public class Contract
{
  public Long id;
  public Collection<ContractItem> items;
}

public class ContractItem
{
  public Long id;
  public Contract contract;
  public Item item;
  public BigDecimal price;
}


I want to query all items and their prices in specified contracts. How can I do it in HQL? In SQL it's solving by simple query:
Code:
SELECT i.id, ci1.price, ci2.price, ...
FROM Items i
  LEFT JOIN ContractItem ci1 ON ci1.item = i.id
  LEFT JOIN ContractItem ci2 ON ci2.item = i.id
  ...
WHERE ci1.contract = ? AND ci2.contract = ? AND ...


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.