0

我无法执行此 HQL 命令:

String hql = "select t.ticketName, t.idTicket, d.jour from Ticket as t inner join DateTraitement as d  on d.idTicket=t.idTicket where t.idTicket= 1";
Query query = getSession().createQuery(hql) ;
List<Abc> result = query.list();

我有这个错误:org.hibernate.QueryException:无法解析属性:idTicket:mmmodel.DateTraitement [从 mmmodel.DateTraitement 中选择 t.ticketName,t.idTicket,d.jour 作为 d,mmmodel.Ticket 作为 t where d。 idTicket = t.idTicket]

这是我的 DateTreatment 课程:

在此处输入代码

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_date_traitement", unique = true, nullable = false)
private Integer idDateTrait;
@Column(name = "jour", length = 50)
private int jour;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_ticket")
private Ticket ticket;

public Integer getIdDateTrait() {
    return idDateTrait;
}

public void setIdDateTrait(Integer idDateTrait) {
    this.idDateTrait = idDateTrait;
}

public int getJour() {
    return jour;
}

public void setJour(int jour) {
    this.jour = jour;
}

public Ticket getTicket() {
    return ticket;
}

public void setTicket(Ticket ticket) {
    this.ticket = ticket;
}

}

我不知道我错过了什么。感谢您的帮助。

4

2 回答 2

0

错误本身解释了问题, ClassDateTreatment应该有 property idTicket

看起来您定义的 Id 是

@Column(name = "id_date_traitement", unique = true, nullable = false)
private Integer idDateTrait;

您可以将其更改为idTicket或在您的查询中使用d.idDateTrait

干杯!!

于 2013-09-04T19:57:37.213 回答
0

试试这个:新问题后更新:

String hql = 
     "select d.ticket.ticketName, d.ticket.idTicket, d.jour 
     from DateTraitment as d
     where d.ticket.idTicket = 1";

Query query = getSession().createQuery(hql) ;

List<Abc> result = query.list();
于 2013-09-04T12:58:07.783 回答