Given three entities A, B and C where B extends A such as :
@Entity
@Table(name = "a")
public class A {
private C c;
//omitted source code
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "c_id", nullable = false)
public C getC() {
return c;
}
public void setC(C c){
this.c=c;
}
}
@Entity
@Table(name = "b")
public class B extends A {
private Integer id;
//omitted source code
}
@Entity
@Table(name = "c")
public class C {
private Integer id;
private String status;
//omitted source code
}
How can I convert to following native SQL to HQL :
select b.* from b b_
inner join a a_ on a_.id=b_.id
inner join c c_ on a_.c_id=c_.id
where c_.status='ACCEPTED';
I tried the following : select b from B b join b.c c where c.status = 'ACCEPTED'
however I get this exception : org.hibernate.QueryException: could not resolve property: c of: B
. I thought Hibernate would resolve the superclass fields at runtime.
What I am trying to achieve here is to ascend the inheritance hierarchy starting exactly from from B
and read the superclass A
inner fields, in particular c
. I wonder if this is doable in hibernate. Otherwise any alternative solution will be more than welcome.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…