[英]how to create a Spring data jpa repository with a clause ON
Suppose we have two classes A and B: Class A:假设我们有两个类 A 和 B:Class A:
public class A {private Long id;}
Class B: Class B:
public class B {private Long id; private String name ; private Boolean isDeleted = false; }
Is there a way to have results of Join query with some other conditions besides the condition ON I tried this but I doesn't work, the compiler doesn't recognize clause ON org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token
:除了条件 ON 之外,有没有办法让 Join 查询的结果与其他条件一起出现,但我没有工作,编译器无法识别子句 ON
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token
:
@Query( "SELECT new com.demo.DTO.resultsDTO(a.id) FROM A ate , B a ON a.id = b.id WHERE b.isDeleted = false AND b.name = ?1 ")
I tried also to include the a.id = b.id in the clause WHERE, but it doesn't return results.我还尝试在 WHERE 子句中包含 a.id = b.id,但它不返回结果。 Please help.
请帮忙。
Your query is off, and is mixing the old-school implicit join syntax with the modern (preferred) join syntax.您的查询已关闭,并且正在将老式隐式连接语法与现代(首选)连接语法混合在一起。 Here is the version you should be using:
这是您应该使用的版本:
SELECT new com.demo.DTO.resultsDTO(a.id)
FROM A a
INNER JOIN B b
ON a.id = b.id
WHERE
b.isDeleted = false AND
b.name = ?1;
Your updated Java code:您更新的 Java 代码:
@Query("SELECT new com.demo.DTO.resultsDTO(a.id) FROM A a INNER JOIN B b ON a.id = b.id WHERE b.isDeleted = false AND b.name = ?1")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.