BigDecimal type and value mismatch in ORM prepared statements

Description

When a BigDecimal type is handed off to hibernate the type is still specified as BigDecimal but the value has been converted to a string. This results in errors like:

class java.lang.String cannot be cast to class java.math.BigDecimal (java.lang.String and java.math.BigDecimal are in module java.base of loader 'bootstrap')

It appears this is a result of a conversion from BigDecimal to String in:
https://github.com/lucee/Lucee/blob/7da911f591481f57b781cda52ea7a2261b161ba8/core/src/main/java/lucee/runtime/db/SQLCaster.java#L106

More details, stacktrace, and reproducible code example in https://dev.lucee.org/t/lucee-6-upgrade-issue-orm-cannot-cast/14029

Environment

Lucee 6+ versions with the ORM extensions (it has been replicated on multiple ORM extension versions including Ortus ORM 6.5.3.104-snapshot)

Attachments

2
  • 10 Sept 2024, 01:46 pm
  • 10 Sept 2024, 12:49 pm

Activity

Show:

Pothys - MitrahSoft 16 September 2024 at 07:45

I have checked this ticket with Lucee versions 6.2.0.84-SNAPSHOT and 6.1.1.85-SNAPSHOT, and the issue has now been resolved. Therefore, I am closing this ticket.

Michael Offner 13 September 2024 at 13:12

fixed the issue, thanks for pointing out.

Michael Offner 13 September 2024 at 13:09

Michael Offner 13 September 2024 at 13:03

Colby Ackerfield 10 September 2024 at 13:46
Edited

I agree, I suspect the change that introduced the bug is the type change from BigDecimal to String on the return of toSqlType in the Types.DECIMAL case in core/src/main/java/lucee/runtime/db/SQLCaster.java. toSqlType() function.

Prior to the commit, the return type was BigDecimal but was changed to String for the NUMERIC/DECIMAL case:

image-20240910-133812.png

I suspect the fix may be as simple as removing the Caster.toString() wrapper and returning return Caster.toBigDecimal(value);


Disabling Precise Math did not fix the issue in the test case or the actual scenario we are experiencing in our code base.

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 6 September 2024 at 16:31
Updated 12 November 2024 at 11:28
Resolved 16 September 2024 at 07:45

Flag notifications