我有一个类似于以下的 JPA 实体 bean:
@Entity
class License {
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "LicenseTags")
Set<Tag> tags;
// Skipped remaining members
}
Tag
它本身也是一个Entity
带有 id 和 name 的。现在我想查询附加了某些标签的许可证。当我尝试以下查询时
Set<Tag> tags = ...;
final QLicense license = QLicense.license;
JPAQuery q = new JPAQuery(entityManager).from(license);
for (Tag tag : tags) {
q.where(license.tags.contains(tag));
}
Collection<License> result = q.listDistinct(license);
我得到以下异常listDistinct
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select distinct license
from License license
where ?1 in elements(license.tags)]: unexpected token [in].
Internal Exception: NoViableAltException(35!=[685:1: inExpression[boolean not, Object left] returns [Object node] : (t= IN n= inputParameter | t= IN LEFT_ROUND_BRACKET (itemNode= inItem ( COMMA itemNode= inItem )* | subqueryNode= subquery ) RIGHT_ROUND_BRACKET );])
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1328)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:425)
at com.mysema.query.jpa.impl.DefaultSessionHolder.createQuery(DefaultSessionHolder.java:35)
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:139)
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:108)
at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:276)
at com.mysema.query.support.ProjectableQuery.listDistinct(ProjectableQuery.java:104)
从解析器异常输出中,我只能猜测可能缺少括号。
我在查询集合中包含的值时做错了什么?
我正在使用 GlassFish Server Open Source Edition 3.0.1 (build 22),而后者又使用 EclipseLink Bundle-Version: 2.0.1.v20100213-r6600
问候,蒂尔曼