I have a entity model like this:
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;
...
}
So I would like to query all the facture from a client X. I try something like this:
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);
}
I get this exception:
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 = ?]
I think it's not possible to query throuth object like this but i don't know how to write this query...
Sorry for my english, i am a french user.
You may have to use inner joins to do this:
select facture
from Facture facture
inner join facture.panier as panier
inner join panier.client as client
where client.clientId = ?
Or use criteria which can be a bit safer since you can't muck up the 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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.