gpt4 book ai didi

java - JPA:对查询键使用 anyOf() 无效

转载 作者:行者123 更新时间:2023-12-01 23:19:59 25 4
gpt4 key购买 nike

我在参与者和抽象实体之间有一对一的关系。我想查询有摘要的参与者。所以我创建以下查询:

@NamedQuery(name = Participant.FIND_ABSTRACT, query = "SELECT p FROM Participant p WHERE p.abstract_ IS NOT EMPTY ORDER BY p.email"),
....
....
@OneToOne
@JoinColumn
private Abstract abstract_;

来自 Abstract.java:

@OneToOne(mappedBy="abstract_")
private Participant participant;

当我尝试使用它时:

public List<Participant> getUploadedAbstract() {
TypedQuery<Participant> query = em.createNamedQuery(Participant.FIND_ABSTRACT, Participant.class);
return query.getResultList();
}

我得到:

Caused by: Exception [EclipseLink-6071] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid use of anyOf() for a query key [org.eclipse.persistence.mappings.OneToOneMapping[abstract_]] not representing a to-many relationship in an expression. Use get() rather than anyOf().
at org.eclipse.persistence.exceptions.QueryException.invalidUseOfAnyOfInExpression(QueryException.java:738)
at org.eclipse.persistence.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:894)
at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:2985)
at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:342)
at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:612)
at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:605)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1300)
at org.eclipse.persistence.internal.expressions.SubSelectExpression.normalizeSubSelect(SubSelectExpression.java:197)
at org.eclipse.persistence.internal.expressions.ExpressionNormalizer.normalizeSubSelects(ExpressionNormalizer.java:93)

......

我哪里错了?

最佳答案

您需要编辑您的命名查询..它应该是

@NamedQuery(name = Participant.FIND_ABSTRACT, query = "SELECT p FROM Participant p WHERE p.abstract_ IS NOT NULL ORDER BY p.email")

IS NOT EMPTY 用于收集。

关于java - JPA:对查询键使用 anyOf() 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20747071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com