我有 HQL 查询
select new PaymentType(o.paymentType.idPaymentType) from Order as o where o.user='1'
它抛出以下异常
org.hibernate.PropertyNotFoundException: no appropriate constructor in class: PaymentType
at org.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:187)
at org.hibernate.hql.classic.QueryTranslatorImpl.renderSQL(QueryTranslatorImpl.java:631)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:220)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
但是我已经声明了必需的构造函数,除此之外,还声明了其他具有不同数量和类型的参数的树构造函数,也没有参数构造函数。
public PaymentType(Integer idPaymentType) {
this.idPaymentType = idPaymentType;
}
编辑:
public class Order implements java.io.Serializable {
private Integer idOrder;
private PaymentType paymentType;
private DeliveryType deliveryType;
...
}