I have some columns with NaN values in my Postgres database. We're handling money so all of my entities are BigDecimals, which can't accomodate NaN.
Is there a setting or something on JPA or Hibernate where I can tell it "Treat any NaNs as if they were NULLS"
CodePudding user response:
You can do that for individual columns with @ColumnTransformer
and can do it programmatically through a MetadataContributor
(see How to provide read and write to ColumnTransofrmer programatically in Hibernate?), but it's not possible to do this globally.
However, if you have NaN in your database, something is wrong already, as you are saving the values with some float/double type. So IMO you should first migrate the data update tbl set col = null where is_nan(col)
and then switch to alter table tbl alter column col set datatype numeric(19,3)
or something like that.