當字符串不是實體映射的關鍵字時,您可以幫助保存一個地圖嗎? 例如:JPA:堅持一個地圖<字符串,實體>
class A {
@Id
long id;
String code;
}
class B {
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@What magical combination of JPA annotations should I use here?!
Map<String,A> mapAByCode;
}
我已經嘗試了很多{@ JoinTable,@ MapKeyColumn,@ JoinColumn,@ JoinTable}註解,但沒有成功的組合,我要瘋了......
謝謝!
爲什麼MapKeyColumn不起作用?查看http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/MapKeyColumns獲取幫助 – Chris
@MapKeyColumn(name =「CODE」)創建一個映射id主鍵的字段(名爲「CODE」)。 @MapKeyColumn(name =「A_CODE」)不起作用 – acimutal
MapKeyColumn定義關係表中用於存儲鍵值的字段。它用於提供額外的信息。您所需要的只是基於A.code值將您的實體散列在地圖中。 – Chris