gpt4 book ai didi

java - 在hibernate中加入不相关的实体(5.1之后)

转载 作者:行者123 更新时间:2023-12-02 02:13:27 24 4
gpt4 key购买 nike

我正在尝试使用 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();

异常(exception):

antlr.SemanticException: Path expected for join!

背景信息

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

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

最佳答案

我的回答是有偏见的,因为我正在开发这项技术。但是FluentJPA将解决您的问题,因为它生成 native SQL。

关于java - 在hibernate中加入不相关的实体(5.1之后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57316534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com