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: H3 - Unable to locate appropriate constructor on class
PostPosted: Fri Sep 16, 2011 9:35 am 
Newbie

Joined: Fri Sep 16, 2011 9:05 am
Posts: 2
Hi, I got this error : Unable to locate appropriate constructor on class :

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();
   }


my persistent bean Vehicule
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; }


I got a link between Vehicle and Entrepot via the field ENTREPOT_CODE.

My work bean Vehicule (to get a Vehicule object) :

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;
   }


Stacktrace :

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


I try to get my object entrepot or ENTREPOT_CODE it doesn't matter actually.
Where am I wrong?

Best regards.


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.