在JPA中获取查询交集? [英] Getting a query intersection in JPA?
本文介绍了在JPA中获取查询交集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:"image" 1:许多"imageToTag"许多:1"tag"
I have: "image" 1:Many "imageToTag" Many:1 "tag"
我想发出一个查询,该查询将返回所有至少具有 标记[a,b,c]的图像.我不清楚如何在JPQL中对此建模.我可以动态地构建查询字符串,但这出于性能和安全性的考虑是不利的.有什么想法吗?
I want to issue a query that will return all images that have at least tags [a, b, c]. It's not clear to me how one can model this in JPQL. I could build the query string dynamically but that's bad for performance and security reasons. Any ideas?
推荐答案
在伪代码中:
SELECT * FROM IMAGES
INNER JOIN IMAGETAGS A
ON IMAGE.ID = A.IMAGEID AND A.TAGID = 'A'
INNER JOIN IMAGETAGS B
ON IMAGE.ID = B.IMAGEID AND B.TAGID = 'B'
INNER JOIN IMAGETAGS C
ON IMAGE.ID = C.IMAGEID AND C.TAGID = 'C'
仅是猜测,但JPQL中的等效值将是
Just guessing, but the equivalent in JPQL would be
Select img from Image img
JOIN img.tag ta
JOIN img.tag tb
JOIN img.tag tc
WHERE ta.description = 'A' and tb.description = 'B' and tc.description = 'C'
这篇关于在JPA中获取查询交集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文