Joda-Money persistence via hibernate

前端 未结 6 2087
情话喂你
情话喂你 2021-02-13 17:58

There is a library for JodaTime that provides Hibernate persistence. Recently I started looking at Joda-Money and started to see how that can be persisted using hibernate and I

6条回答
  •  一整个雨季
    2021-02-13 18:56

    Based on http://jadira.sourceforge.net

    Money Types typically consist of a currency and amount. Jadira makes it possible to store only the amount to the database with the currency configured using a parameter. For example:

    @Column
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
        parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "USD")})
    private Money money;
    
    Alternatively, with other types two columns to hold the amount an currency:
    
    @Columns(columns = { @Column(name = "MY_CURRENCY"), @Column(name = "MY_AMOUNT") })
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
    private Money money;
    

提交回复
热议问题