【发布时间】:2011-04-03 15:46:07
【问题描述】:
应该在 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。
我浏览过http://docs.jboss.org/hibernate/annotations/3.4/reference/en/html/entity.html#entity-mapping-association-collections,但很快就迷路了。
澄清:currency 列应同时用于映射键和 Credit 对象的货币字段。
这在 Hibernate 中可行吗?
【问题讨论】: