Skip to content

Persisting FastMoney in JPA truncates amount #102

@Lacuno

Description

@Lacuno

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions