1

我有一个最喜欢的对象。这个对象与颜色有多对多的联系。可以说一些收藏夹有很多颜色,2-3 等。当我搜索收藏夹时:

SELECT fav FROM Favourite fav join fetch fav.colors as cl WHERE fav.name = "blabla" .

生成的对象包含与此收藏相关的所有颜色。我的问题是当我想搜索具有某种颜色的收藏夹时。例如:

SELECT fav FROM Favourite fav join fetch fav.colors as cl WHERE cl.name = "red" 

然后生成的对象仅包含红色。结果,我想获得包含“红色”颜色的收藏对象,但也显示所有相关颜色。有什么建议么?提前致谢。

4

1 回答 1

1

Well finally it worked with an inner query and "EXISTS" operator. (color is an object of , int id and string name).

SELECT fav FROM Favourite fav join fetch fav.colors as cl WHERE EXISTS ( SELECT fav2 FROM Favourite fav2 join fetch fav2.colors as cl2 WHERE fav2.id = fav.id AND cl2.name = "red" )
于 2012-08-31T11:15:17.790 回答