休眠到许多反向查询
hibernate on to many reverse query
我在 2 个实体 Question
和 Answer
之间有 many2one 关系,在 Answer' and no one2many defined in
Question` 中定义了 many2one。
如果不在 Question
实体中添加 one2many 关系,我如何使用 hibernate 查询没有任何答案的问题?
类似于:
select distinct q from Question q
left join Answer a on a.question_id=q.id
where a.id is null
像这样:
select q from Question q
where q not in (select a.question from Answer a)
顺便说一句,您提供的查询是 "too much SQL",请记住,虽然它们的语法相似,但 SQL 和 JPQL 在概念上是不同的。
我在 2 个实体 Question
和 Answer
之间有 many2one 关系,在 Answer' and no one2many defined in
Question` 中定义了 many2one。
如果不在 Question
实体中添加 one2many 关系,我如何使用 hibernate 查询没有任何答案的问题?
类似于:
select distinct q from Question q
left join Answer a on a.question_id=q.id
where a.id is null
像这样:
select q from Question q
where q not in (select a.question from Answer a)
顺便说一句,您提供的查询是 "too much SQL",请记住,虽然它们的语法相似,但 SQL 和 JPQL 在概念上是不同的。