Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from mysql decimal column to curreny YEN fails. #95

Open
runkelstein opened this issue Aug 12, 2020 · 2 comments
Open

Conversion from mysql decimal column to curreny YEN fails. #95

runkelstein opened this issue Aug 12, 2020 · 2 comments

Comments

@runkelstein
Copy link

runkelstein commented Aug 12, 2020

Hey Folks,

for an application we are using hibernate as ORM MApper and jadira for the conversion into java types.

We are converting from a mysql column decimal(19,2) into Yoda Money.

Our billing application now needs to support YEN. To all the currencies so far there is one crucial difference:

YEN does not have decimal places. Still it makes sense to store all the amounts into the same columns.

image

When you look at the code of yoda money, you see that yoda money will throw an exception if a big decimal with decimal points is provided.

The jadira converter (PersistentMoneyAmountAndCurrency) looks like this:

image

Now mysql will store for instance the amount '0' as '0.00' in the database. When converting to bigdecimal this value now has a scale. I think it is fixable by changing the code in the method "fromConvertedColumns".

For now I will just duplicate this class and make these changes myself.

@runkelstein
Copy link
Author

image

This is, what works for me. I assume the method "setScale" from BigDecimal will throw an aritmethic exception, if the values and the currency will not match.

image

Of course if this is a proper solution for all uses cases and if this is ready for including into the library, I don't know. For my use case for now, it seems like it get a bit further.

@runkelstein
Copy link
Author

There are also overloads for money which can be used instead:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant