0

我有一个这样的实体模型:

public class Facture implements Serializable 
{
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_FACTURE")
private long idFacture;
...

private Panier panier;
    ...
 }

 public class Panier
 {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_PANIER")
private long idPanier;  

@ManyToOne
private Client client;
@OneToMany
private List<LignePanier> articles = new ArrayList<LignePanier>();
...
 }

 public class Client
 {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_CLIENT")
private long idClient;
...
  }

所以我想从客户端 X 查询所有的事实。我尝试这样的事情:

 public List<Facture> listeFacture(Long clientID) {
    List<ParameterMap> parameters = new ArrayList<ParameterMap>();
    parameters.add(new ParameterMap(StandardBasicTypes.LONG, clientID));
    return dao.query("select facture from Facture facture where facture.panier.client.idClient = ?", parameters);
}

我得到这个例外:

  org.hibernate.QueryException: could not resolve property: client of: be.infoserv.web.model.Facture [select facture from be.infoserv.web.model.Facture facture where facture.panier.client.idClient = ?]

我认为不可能像这样查询通过对象,但我不知道如何编写这个查询......

对不起我的英语,我是法国用户。

4

1 回答 1

1

您可能必须使用内部连接来执行此操作:

select facture
from Facture facture
     inner join facture.panier as panier
     inner join panier.client as client
where client.clientId = ?

或者使用可以更安全的标准,因为你不能搞砸 hql:

Criteria factureCrit = session.createCriteria(Facture.class);
Criteria panierCrit = factureCrit.createCriteria("panier");
Criteria clientCrit = panierCrit.createCriteria("client");
clientCrit.add(Restrictions.idEq(clientId));

return factureCrit.list();
于 2012-08-01T19:56:44.600 回答