I'm using JodaMoney library and the Jadira User types to store monetary values. I want to be able to store a single currency per table, instead of needing so many fields.
Is there a way to map the currencies to the same field? This doesn't work because it complains I can't mix insertable and updatable.
@Columns(columns = {@Column(name = "currency"), @Column(name = "productsAmount")})
@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
private Money totalProducts;
@Columns(columns = { @Column(name = "currency", insertable = false, updatable= false), @Column(name = "orderTotalAmount") })
@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
private Money orderTotalAmount;
I tried this with
org.jadira.usertype.moneyandcurrency.moneta.PersistentMoneyAmountAndCurrency
as well and get the same error as you do:A quick and dirty solution is already proposed in this SO answer, and more specifically the first point: Instead of going with Jadira, he suggests using transient fields.
I myself don't feel really comfortable with this approach as a long term solution, so I'll look into implementing a
UserType
, as suggested at the second point of the same SO answer.If I ever have a working implementation I'll post it back here.
ps: There's also @org.hibernate.annotations.Parameter solution(name = "currencyCode", value = "USD") solution which I guess doesn't fit your use-case since it's hardcoding the currency in the annotation.