0

以下命名查询

 <named-query name="fix.getByProblem">
        <query>
            SELECT f
            FROM Fix f JOIN f.solved s
            WHERE s.id IN :ids
        </query>
    </named-query>

应该返回解决至少一个给定问题的所有修复程序,但失败并显示错误消息

异常描述:编译查询时出错 [fix.getByProblem]:

SELECT f FROM Fix f JOIN f.solved s WHERE s.id IN :ids

],类 [ProblemHandle] 的未知状态或关联字段 [id]。

模型如下:(简化)

修复.java

@ElementCollection
@CollectionTable(name = "FIX_SOLVED", schema = SCHEMA_NAME, joinColumns = {@JoinColumn(name = "SOURCE_VERSION", referencedColumnName = "version")})
@AttributeOverrides({ @AttributeOverride(column = @Column(name = "SOLVED_ID", nullable = true), name = "id") })
private Collection<ProblemHandle> solved;

问题句柄.java

@Embeddable
@Access(AccessType.PROPERTY)
public class ProblemHandle {
    private Long id;
...
}

问题.java

    @Entity(name = Problem.ENTITY_NAME)
    @Access(value = AccessType.FIELD)
    @Table(name = Problem.TABLE_NAME, schema = Problem.SCHEMA_NAME)
    @IdClass(ProblemHandle.class)
    public class Problem {
        public static final String ENTITY_NAME = "problem";
        public static final String SCHEMA_NAME = "X";
        public static final String TABLE_NAME = "PROBLEM";

        @Id
        @Column(name="id", nullable = false)
        private Long id;
...
}

我怎样才能在不改变模式的情况下实现这一点,例如使用句柄?

4

1 回答 1

0

你有@Access(AccessType.PROPERTY),所以你的属性的名字来自你的get方法,而不是变量。您的 get 方法的名称是什么?

尝试删除 @Access(AccessType.PROPERTY)

另外,你用的是什么版本?尝试使用 2.4 版本。

于 2012-08-27T14:53:25.563 回答