HQL中的内部联接

时间:2013-09-04 12:54:00

标签: java hibernate select hql

我无法执行此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 [选择t.ticketName,t.idTicket,d.jour来自mmmodel.DateTraitement为d,mmmodel。票证为d,其中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;
}

}

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

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分:0)

错误本身自我解释了问题,类DateTreatment应该具有属性idTicket

看起来您定义的ID是

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

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

干杯!!