的follwing命名查詢JPQL NamedQuery:從@ElementCollection的@Embeddable類的訪問屬性引用
<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]:
,選擇F FROM修復˚FJOIN f.solved S其中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;
...
}
我怎樣才能做到這一點,而不必改變模式,例如使用手柄?
您有'ProblemHandle'類中的'id'還有其他字段嗎? –
嘗試在問題處理中標記@Transient通過id字段。 – JMelnik
感謝您的回覆。 ProblemHandle沒有任何其他字段,但是有兩個私有常量。我嘗試了@Transient,但沒有任何效果。你背後的想法是什麼? – user1346605