gpt4 book ai didi

java - Hibernate 中的 map 注释?

转载 作者:行者123 更新时间:2023-12-01 05:47:45 26 4
gpt4 key购买 nike

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 中可能吗?

最佳答案

这是我使用的一种变体。一般来说,使用@ElementCollection@ManyToMany注释,其他注释根据具体情况而定。

@ElementCollection
@Column(name = "value", nullable=false)
@MapKeyColumn(name="name")
@JoinTable(name = "from_to", joinColumns = @JoinColumn(name = "to_id"))
Map<String, String>

关于java - Hibernate 中的 map 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5530611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com