1
应该在User类的creditBalances字段上注释什么?在Hibernate中映射注释?
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;
}
User类
@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
对象的映射关键字和货币字段。
这可能在休眠?
ElementCollection在3.5中添加。我如何在3.4中做到这一点?作为一种可嵌入的方式,Credit在这方面没有ID或自己的表格。 – Gabriel 2011-04-04 07:58:41
'@ CollectionOfElements'。查看嵌入的[documentation](http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-ofvalues)。 – 2011-04-04 12:08:22