我遇到了hibernate 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);
我的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;
}
}
我在控制台中收到以下错误:
Caused By: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join!
答案 0 :(得分:0)
您需要在@OneToMany
和@OneToOne
之间建立关联(Person
,PhisicalPerson
)。有了这样的关联,你就不需要where
条款
SELECT NEW es.criteria.crc.model.queryObjects.NameQuery(pf.name)
FROM Person as p INNER JOIN p.pf
在示例中pf
是Person
的属性,与PhisicalPerson
相关联。
class Person {
@OneToOne(mappedBy = "person")
private PhisicalPerson pf;
}
class PhisicalPerson {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_person")
private Person person;
}