Reputation: 2030
Having a cast like this:
SELECT
CAST(a * 100000000 as big_integer)
FROM
Amount
WHERE
id = :id
Generate this SQL:
prepareStatement(
"select cast(amount0_.\"a\"*100000000 as numeric(19, 2)) from \"AMOUNT\" where amount0_.\"id\"=?");
Question: Why two decimal places though?
There are some other problems
Using:
Upvotes: 3
Views: 48
Reputation: 76943
A similar question was asked here. The solution boiled down to something like
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
typeContributions.getTypeConfiguration().getDdlTypeRegistry().addDescriptor(
new DdlTypeImpl(SqlTypes.NUMERIC, "numeric", this)
);
and casting to BigDecimal
. The reasoning, as Beikov presented was
You can register a custom DdlType into DdlTypeRegistry in a TypeContributor for the NUMERIC/DECIMAL type code. The custom DdlType can then override getCastTypeName to return just numeric if length and precision are null.
This would be a nice improvement for Hibernate ORM though, so if you could create a Jira improvement ticket in our issue tracker and possibly also provide a PR with the improvement, chances are good that we will accept this
Upvotes: 0