JadiraOrg / jadira

Jadira Framework
Apache License 2.0
74 stars 44 forks source link

Persisting FastMoney in JPA truncates amount #102

Open Lacuno opened 3 years ago

Lacuno commented 3 years ago

I am persisting a FastMoney instance with jadira the following way:

@Entity
public class MyEntity {
    @Columns(columns = {@Column(name = "currency"), @Column(name = "amount")})
    @Type(type = "org.jadira.usertype.moneyandcurrency.moneta.PersistentFastMoneyAmountAndCurrency")
    @NotNull
    private FastMoney amount;
}

This works for simple cases like FastMoney.of(100, "EUR") very well but fails if we add decimal values. E.g. FastMoney.of(100.23, "EUR") will be present in a MyEntity object but after persisting the value 100 EUR will be present in the corresponding table.

I found the following workaround:

@Entity
public class MyEntity {
    @Columns(columns = {@Column(name = "currency"), @Column(name = "amount")})
    @Type(type = "org.jadira.usertype.moneyandcurrency.moneta.PersistentFastMoneyMinorAmountAndCurrency")
    @NotNull
    private FastMoney amount;
}

If I use PersistentFastMoneyMinorAmountAndCurrency it works as expected and 100,23 will be correctly inserted into the DB. Is that intended behavior?

Thanks!