gpt4 book ai didi

java - 如何在 Hibernate 中使用 org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency 类型映射 Joda Money?

转载 作者:搜寻专家 更新时间:2023-11-01 01:52:46 25 4
gpt4 key购买 nike

试试这个:

@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
private org.joda.money.Money price;

得到这个:

org.hibernate.MappingException: property mapping has wrong number of columns:domain.ClientOrderItem.price type: org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency


@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "USD")})

效果很好,但我想将货币存储在数据库中并能够使用不同的货币。

最佳答案

有一个工作示例来自 Jadira Usertype Unit Tests

    @Entity
@Table(name = "moneyAmountAndCurrency")
@TypeDef(name = "testjoda_MoneyAmountWithCurrencyType", typeClass = PersistentMoneyAmountAndCurrency.class)
public class MoneyAmountAndCurrencyHolder implements Serializable {

private static final long serialVersionUID = -1674416082110551506L;

@Columns(columns = { @Column(name = "MY_CURRENCY"), @Column(name = "MY_AMOUNT") })
@Type(type = "testjoda_MoneyAmountWithCurrencyType")
private Money money;

关于java - 如何在 Hibernate 中使用 org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency 类型映射 Joda Money?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20570560/

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