此表达式中的字段在此上下文中具有无效表

时间:2015-05-10 12:19:20

标签: java jpa

我试图进行以下查询:

@NamedQuery(name="Grade.findGradeByClassGroup", 
            query= "SELECT gr From Grades gr join DeterminateTable d on gr.DeterminateTableId = d.DeterminateTableId join SchoolYears sy on gr.GradeId = sy.GradeId join ClassGroups cg on cg.schoolYear = sy.YearInt where cg.groupId = :classGroup")

我得到了这个例外:

Caused by: Exception [EclipseLink-6069] (Eclipse Persistence Services - 2.6.0.v20141202-3914740): org.eclipse.persistence.exceptions.QueryException
Exception Description: The field [Grades.GradeId] in this expression has an invalid table in this context.
Query: ReadAllQuery(name="Grade.findGradeByClassGroup" referenceClass=Grade jpql="SELECT gr From Grades gr join DeterminateTable d on gr.DeterminateTableId = d.DeterminateTableId join SchoolYears sy on gr.GradeId = sy.GradeId join ClassGroups cg on cg.schoolYear = sy.YearInt where cg.groupId = :classGroup")
    at org.eclipse.persistence.exceptions.QueryException.invalidTableForFieldInExpression(QueryException.java:755)
    at org.eclipse.persistence.internal.expressions.FieldExpression.validateNode(FieldExpression.java:325)
    at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:3291)
    at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:369)
    at org.eclipse.persistence.internal.expressions.FieldExpression.normalize(FieldExpression.java:225)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.normalize(CompoundExpression.java:224)
    at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:574)
    at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:865)
    at org.eclipse.persistence.expressions.ExpressionBuilder.normalize(ExpressionBuilder.java:267)
    at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:363)
    at org.eclipse.persistence.internal.expressions.FieldExpression.normalize(FieldExpression.java:225)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.normalize(CompoundExpression.java:232)
    at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:574)
    at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:865)
    at org.eclipse.persistence.expressions.ExpressionBuilder.normalize(ExpressionBuilder.java:267)
    at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:363)
    at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:758)
    at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:671)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.normalize(CompoundExpression.java:224)
    at org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:574)
    at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1474)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQueryMechanism.java:550)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1722)
    at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:867)
    at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:798)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:666)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:909)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:615)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:342)
    ... 65 more

我无法弄清楚什么是错的,试图谷歌但无法得到任何答案......

导致这种情况的原因是什么?

0 个答案:

没有答案