Ralf Grewe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzRkNmI1Njhk...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16650?atlOrigin=eyJpIjoiNzRkNm...
) HHH-16650 (
https://hibernate.atlassian.net/browse/HHH-16650?atlOrigin=eyJpIjoiNzRkNm...
) Loss in precision due usage of Float data type instead of BigDecimal in case Oracle JDBC
driver returning -127 for scale and 0 for precision if precision/scale is unknown. Might
happen unexpectedly and requires very close inspection of used SQL (
https://hibernate.atlassian.net/browse/HHH-16650?atlOrigin=eyJpIjoiNzRkNm...
)
Issue Type: Bug Affects Versions: 6.2.3 Assignee: Unassigned Components: hibernate-core
Created: 20/May/2023 09:06 AM Environment: Hibernate: 6.2.3
OS: CentOS 8
JRE: Java 17.0.7
DB: Oracle 19.14.0.0.0 Priority: Critical Reporter: Ralf Grewe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
Dear Hibernate Team,
The Oracle JDBC Driver generally returns a value of “-127” for method
"getScale()" and a value of “0” for method "getPrecision()" (on
“OracleResultSetMetaData”) in case the scale and the precision of a returned numeric
column is unknown. Starting with Hibernate 6, Hibernate will return the data as Float data
type (according to “'org.hibernate.dialect.OracleDialect.resolveSqlTypeDescriptor()”)
instead of BigDecimal (in previous versions). From my point of view, this is a pretty bad
design decision as it:
* breaks existing code which uses native queries (which do not feature explicit type
mappings via ‘addScalar’)
* even worse: causes loss in predictability and loss in precision, e.g., a SQL query
like:
SELECT col1 FROM testTable UNION ALL 123.54356 AS col1 FROM DUAL
will return “col1” as Float value EVEN if you specify “col1” as NUMBER(38,0)!! Data loss
is garuanteed. Basically it means, that SQL queries that do not look as being problematic
at the first glance, may reveal as such at a much closer look. If code features hundreds
of native queries, you need to closely inspect each of them (not that I’m a big fan of
native queries but sometimes it is was it is…)
If Oracle returns a value of “-127” for method "getScale()" and a value of “0”
for method "getPrecision() it simply mean that precision and scale are unknown and in
such case using BigDecimal is the right decision whereas Float data type is definitely
not.
Bye,
Ralf
(
https://hibernate.atlassian.net/browse/HHH-16650#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16650#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:9dd72a2 )