Bonjour j'ai une erreur Unable to locate appropriate constructor on class lorsque je passe dans une requête :
Code:
public List<com.entreprise.xxx.bean.Vehicule> getVehiculesByVersion(String versionCode) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<com.entreprise.xxx.bean.Vehicule> criteria = builder.createQuery(com.entreprise.xxx.bean.Vehicule.class);
Root<AnswerVersion> root = criteria.from(AnswerVersion.class);
Join<AnswerVersion, Answer> versionAnswers = root.join("answers");
Join<Answer, Marque> answerMarque= versionAnswers.join("marque");
Join<Marque, Vehicule> marqueVehicule = answerMarque.join("vehicule");
criteria.select(builder.construct(com.entreprise.xxx.bean.Vehicule.class,
marqueVehicule.get("code"), marqueVehicule.get("name"), marqueVehicule.get("entrepot"))).distinct(true);
criteria.where(builder.equal(root.get("code"), versionCode));
criteria.orderBy(builder.asc(marqueVehicule.get("name")));
return em.createQuery(criteria).getResultList();
}
Mon bean Vehicule de persistance
Code:
@Id
@Column(name="CODE", length=3)
private String code;
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
@Column(name="NAME", length=50, nullable=false)
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@ManyToOne(targetEntity=Entrepot.class)
@JoinColumn(name="ENTREPOT_CODE", nullable=false)
private Entrepot entrepot;
public Entrepot getEntrepot() { return Entrepot; }
public void setEntrepot(Entrepot entrepot) { this.Entrepot = entrepot; }
J'ai donc une liaison entre mon véhicle et mon entrepot via le champ ENTREPOT_CODE.
Mon bean Vehicule côté métier (pour récupérer un objet Vehicule) :
Code:
public Vehicule() {}
public Vehicule(String code, String name, Entrepot entrepot) {
super();
this.code = code;
this.name = name;
this.entrepot = entrepot;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setEntrepot(Entrepot entrepot) {
this.entrepot = entrepot;
}
public Entrepot getEntrepot() {
return entrepot;
}
trace de l'erreur :
Code:
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.entreprise.xxx.bean.Vehicule] [select distinct new com.entreprise.xxx.bean.Vehicule(generatedAlias0.code, generatedAlias0.name, generatedAlias0.entrepot) from com.entreprise.xxx.persistence.bean.AnswerVersion as generatedAlias1 inner join generatedAlias1.answers as generatedAlias2 inner join generatedAlias2.marque as generatedAlias3 inner join generatedAlias3.vehicule as generatedAlias0 where generatedAlias1.code=:param0 order by generatedAlias0.name asc]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:302)
... 39 more
Je cherche à récupérer mon objet entrepot (ou bien son ENTREPOT_CODE aucune importance), actuellement il m'est impossible de résoudre cette requête, où est mon erreur s'il vous plait ?