以下命名查询
<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]。
模型如下:(简化)
Fix.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;
ProblemHandle.java
@Embeddable
@Access(AccessType.PROPERTY)
public class ProblemHandle {
private Long id;
...
}
Problem.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;
...
}
如何在不改变模式的情况下实现这一目标,例如:使用句柄?
答案 0 :(得分:0)
您有@Access(AccessType.PROPERTY),因此您的属性名称来自您的get方法,而不是变量。 get方法的名称是什么?
尝试删除@Access(AccessType.PROPERTY)
另外,您使用的是哪个版本?尝试使用2.4版本。