3
我對JPA(和我用作提供者的Hibernate)還是一個新的東西,所以也許這不可能是做了,但無論如何...在JPA中,一個嵌入值的映射,有一個嵌入式實體用作密鑰
考慮下面的代碼:
@Entity
class Root {
@Id
private long id;
private String name;
@ElementCollection
private Map<ResourceType, Resource> resources;
...
}
@Entity
class ResourceType {
@Id
private long id;
private String name;
}
@Embeddable
class Resource {
private ResourceType resourceType;
private long value;
}
在數據庫中,有一個採集表「 Root_resources」,即存儲地圖的價值,但出現的資源類型兩次(實際上是資源類型ID),一次作爲地圖的KEY,一次作爲值的一部分。
有沒有類似於說@MapKey
註解的方法來表示鍵是值的列之一(即嵌入)?
您是否找到解決方案?下面的工作是否正常? – Unda 2014-06-06 10:33:14
[@ElementCollection with Map其中實體是Embeddable的字段]的可能重複(https://stackoverflow.com/questions/11974096/elementcollection-with-mapentity-embeddable-where-entity-is-一個場的最-e)中 –
Jules
2017-11-30 21:11:49