在休眠中连接无关实体(5.1之后)

时间:2019-08-01 20:25:48

标签: java spring hibernate jpa spring-data-jpa

我正在尝试使用在Hibernate 5.1之后添加的新的“ ON”子句。我试图在未关联的表/实体上运行查询,但出现异常提示我的语法错误。

代码

System.out.println(org.hibernate.Version.getVersionString()); //5.3.7.Final

String query = " SELECT i FROM Information i JOIN Cat c ON i.catId = c.id JOIN Data d ON c.data.id = d.data.id WHERE i.isNew = false AND i.creationTimestamp <= :offset";

Query typedQuery = entityManager.createQuery(query);
typedQuery.setMaxResults(fetchSize);
typedQuery.setParameter("offset", currentTimestamp);

return typedQuery.getResultList();

例外:

antlr.SemanticException: Path expected for join!

背景信息

我的语法似乎与休眠功能版本中使用的语法相同-> https://in.relation.to/2016/02/10/hibernate-orm-510-final-release/

我还遵循了本教程中使用的语法-> https://thoughts-on-java.org/how-to-join-unrelated-entities/

1 个答案:

答案 0 :(得分:0)

自从我开发这项技术以来,我的回答就带有偏见。但是FluentJPA会解决您的问题,因为它会生成本机SQL。