Hi Sebastian.What data type do amount use? I've tried use BigDeci

Hi Sebastian.

What data type do amount use? I've tried use BigDecimal, and create a custom converter MonetaryAmount to BigDecimal, but the error still appeared.

The conversion goes wrong when there is no currency selected. Looks like a bug.

Amount should be any javax.money.MonetaryAmount class, no BigDecimal or anything else. So e.g. org.javamoney.moneta.FastMoney

The whole idea behind MoneyField is that you don't have an amount and currency field in your domain and ui, but instead a Money field based on JSR354 javax.money.MonetaryAmounts (including both amount and currency)

This allows the user not only to select currencies, but to do e.g. (historic) conversions between currencies. And of course it simplifies your domain having just one field instead of 2 (e.g. annotated with @CompositeType(io.hypersistence.utils.hibernate.type.money.MonetaryAmountType.class) for mapping into relational DBs)

Which conversion goes wrong? Can you please provide a test or some further info. In the MoneyField code there is only one conversion (from the text-field amount and combobox currency to org.javamoney.moneta.Money) and it does not happen when currency is empty.

Hi Sebastian..

Sorry for the late update.

So, previously I've used the com.vaadin.flow.data.converter.Converter to convert the MonetaryAmount to BigDecimal, since my data layer uses BigDecimal data type, but still failed.

Now it is perfectly worked after following this guide java - How to properly map MonetaryAmount using Hibernate? - Stack Overflow . I need to change the Amount data type to MonetaryAmount and convert it using jakarta.persistence.AttributeConverter .


Thank you.

Yes that will work, if you just need to store the amount and not the currency. In this case you will probably have a fixed currency in MoneyField:

MoneyField money = new MoneyField("Amount", "EUR"); // or ("Amount", "EUR", true); to allow basic calculations
money.setCurrencyReadOnly(true);