[英]Map Annotation in Hibernate?
在User類的creditBalances字段上應該添加什么注釋?
credit_balance表
CREATE TABLE `credit_balance` (
`user_id` varchar(255) NOT NULL,
`currency` char(3) DEFAULT NULL,
`amount` decimal(12,4) DEFAULT NULL
)
信用等級
@Embeddable
public class Credit {
@Column(name="currency", columnDefinition="CHAR(3)", nullable=false)
Currency currency;
@Column(name="amount", columnDefinition="DECIMAL(12,4)", nullable=false)
BigDecimal amount;
}
用戶類別
@Entity
public class User {
@Id
String id;
//What annotation goes here?
Map<Currency, Credit> creditBalances;
}
我們正在使用Hibernate 3.4。
說明: currency
列應同時用於地圖鍵和Credit
對象的貨幣字段。
在Hibernate中有可能嗎?
這是我使用的一種變體。 通常,使用@ElementCollection
或@ManyToMany
批注,其他則視情況而定。
@ElementCollection
@Column(name = "value", nullable=false)
@MapKeyColumn(name="name")
@JoinTable(name = "from_to", joinColumns = @JoinColumn(name = "to_id"))
Map<String, String>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.