5

I'm interested in incorporating JSR 354 Money API into my application and would like to be able to map MoneyAmount as Embeddable with JPA but we do not seem able to because the no-arg constructor of the Moneta implementation class is private and JPA (or at least Hibernate) requires it to be protected.

We tried to extend it to provide a protected constructor, but the class is final so can't to do that either.

First, assuming:

  1. I'm not the only one who might want to do that and
  2. Interoperability with JPA is important to this JSR

I'd suggest the spec to be enhanced to require implementations to provide a protected constructor for this purpose?

Secondly, would the Moneta RI team consider loosening the default arg constructor access to protected level? It should not have any downside if the class is final anyway?

Thirdly, if this change might take a while, can anyone think of an elegant workaround in the meantime (other than forking our own implementation)?

TheArchitect
  • 2,161
  • 1
  • 12
  • 16
  • I think the best way to use money's type is to implements a simple jpa attribute converter – gtosto Dec 09 '17 at 17:33
  • but then it makes for ugly indirection when performing operations e.g. entity.getMyMoney().getMonetaryAmount().add(otherEntity.getMyMoney().getMonetaryAmount()) - it's kind of heavy... – TheArchitect Dec 13 '17 at 01:23

1 Answers1

2

Jadira User Types has support of Moneta types maybe it can solve your problem.

Sergey Ponomarev
  • 2,947
  • 1
  • 33
  • 43
  • 1
    PersistentMoneyAmountAndCurrency doesn't seem to implement MonetaryAmount so it is equivalent to wrapping option which I can implement easily on my side but creates a lot of ugly indirection when performing operations e.g. entity.getJaridaMoney().getMonetaryAmount().add(otherEntity.getJadiraMoney().getMonetary‌​Amount()) - it's kind of heavy... – TheArchitect Dec 13 '17 at 01:39