0
我要排除加有與下面的JPQL查詢特定標籤的物品:排除項目與JPQL「不」
select distinct i from Item i join i.tags t where t not in (:excludedTags)
它的工作原理如果item
只有一個tag
這tag
在excludedTags
名單。但是如果在item
上還有其他tag
,它仍會被選中!
模型的相關部分:
@Entity
class Tag {
@ManyToMany(mappedBy="tags")
var items
}
@Entity
class Item {
@ManyToMany
var tags
}
我怎樣才能排除有JPQL排除任何標籤的物品?
謝謝。它作爲一個輕微的變體:'...不存在(從項目i2中選擇標籤加入i2.tags標籤,其中i2.id = i.id和標籤在(:excludedTags))''中。據我所知,由於存在一個休眠錯誤,需要'excludedTags'附近的括號。 – deamon 2013-03-14 08:35:36
該bug已經在更新版本中得到修復。 – 2013-03-14 08:58:47
我使用的是4.1.9,不是那麼古老。 – deamon 2013-03-14 10:21:35