1

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; 
Richard G
  • 5,243
  • 11
  • 53
  • 95

1 Answers1

0

I tried this with org.jadira.usertype.moneyandcurrency.moneta.PersistentMoneyAmountAndCurrency as well and get the same error as you do:

org.hibernate.AnnotationException: Mixing insertable and non insertable columns in a property is not allowed

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.

Community
  • 1
  • 1
Kostas Filios
  • 718
  • 1
  • 9
  • 13