[英]Path expected for join hibernate
I have a problem with hibernate HQL
queries and simple INNER JOIN 休眠
HQL
查询和简单的INNER JOIN有问题
String hql = "SELECT NEW es.criteria.crc.model.queryObjects.NameQuery(pf.name) FROM Person as p INNER JOIN PhisicalPerson as pf WHERE pf.idPersona = p.idPersona";
return personService.query(hql);
My Java file has the following code: 我的Java文件具有以下代码:
public class NameQuery{
private String name;
public NameQuery(String name) {
super();
this.name= name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
}
I recieve the following error in console: 我在控制台中收到以下错误:
Caused By: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join!
You need to have an association ( @OneToMany
, @OneToOne
) between Person
and PhisicalPerson
. 你需要有一个协会(
@OneToMany
, @OneToOne
之间) Person
与PhisicalPerson
。 Having such an association you don't need the where
clause 具有这种关联,您不需要
where
子句
SELECT NEW es.criteria.crc.model.queryObjects.NameQuery(pf.name)
FROM Person as p INNER JOIN p.pf
In the example pf
is a property of Person
, associated to PhisicalPerson
. 在示例中,
pf
是与PhisicalPerson
关联的Person
的属性。
class Person {
@OneToOne(mappedBy = "person")
private PhisicalPerson pf;
}
class PhisicalPerson {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_person")
private Person person;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.