我的项目中有很多实体,我想使用 HQL 查询从多个实体中检索数据。在 HQL 查询中,我尝试使用 JOINS 从 Entities 检索数据,但在执行代码时会生成异常。以下是例外:
org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [SELECT s.id, s.name, s.url, s.uuid, s.createdBy , t.id , u.id , u.name FROM com.insonix.qrata.models.Site s INNER JOIN s.topics t INNER JOIN User u WHERE lower(s.name) LIKE lower(:name) AND s.createdBy IN (:created_by) AND u.id = s.createdBy]
以下是查询:
SELECT s.id, s.name, s.url, s.uuid, s.createdBy , t.id , u.id , u.userinfo.firstname , u.userinfo.lastname FROM Site s INNER JOIN s.topics t INNER JOIN User u WHERE lower(s.name) LIKE lower(:name) AND s.createdBy IN (:created_by) AND u.id = s.createdBy
以下是我的实体:
public class CommonEntity {
-------------------
private Long createdBy;
private String uuid;
------------------------
}
public class Site extends CommonEntity{
private long id;
private String url;
private String name;
private Category category;
private List<Topic> topics = new ArrayList<>(0);
---------------------------
}
public class Topic extends CommonEntity{
private int id;
private List<Site> sites = new ArrayList<Site>(0);
-----------------------------------
}
public class User extends CommonEntity
private long id;
private UserInfo userinfo;
--------------------------------
}
public class UserInfo extends CommonEntity{
private String firstname;
private String lastname;
}