I\'m using hibernate and hql for querying in my Java codes. But I got an exception like this:
Caused by: org.hibernate.PropertyNotFoundException: Could not f
Problem found:
Even if the HQL can be translated to sql correctly, but when ResultTransformer gets the result, there will be only 3 fields in the result:
1. A
2. length
3. unit
No matter how many fields in A, they will be aggregated into a single field "A" and since I didn't set any alias to this field, it will be treated as "field 0".
So the problem solved after I changed the HQL like this:
select a.id as id, a.name as name, sum(c.length) as length, min(c.unit) as unit
from A a
left outer join a.b as b
left outer join b.c as c
group by
a.id
a.name
@Access(AccessType.FIELD)
add getter and setter of every field
@Entity
@Table(name="A")
@Access(AccessType.FIELD)
class A
{
@Id
@Column(name="A_ID", updatable=false)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id= id;
}
}