Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-16986 (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiMDMwMj...
)
Re: CoercionException caused by attempted coercion of query param to entity field type (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiMDMwMj...
)
But, upon closer inspection, it’s a bit hard to argue that this particular query is
something that Hibernate could possibly accept.
If I have a query like select 2 * ?1 , Hibernate has to assign a type to the query result
before returning a Query object to the program, and in this case it can't know that
type until Query.setParameter() is called.
So, it does the best it can do, and infers that ?1 must be an integer type. Which is
pretty reasonable.
And then when you try to bind a non-integral value to that parameter by calling
setParameter() , you receive:
java.lang.ArithmeticException: Rounding necessary
which is also not unreasonable. (Silently truncating the BigDecimal seems worse to me.)
So I don’t see this case as fixable.
That said, there are some related cases where we probably could do better, and there’s
actually an existing issue related to this:
https://hibernate.atlassian.net/browse/HHH-16102.
In particular, this query:
session.createQuery( "SELECT 1 WHERE 2 * ?1 > 0" )
.setParameter(1, BigDecimal.valueOf(123.446))
.getSingleResult();
is one that we probably should accept.
(
https://hibernate.atlassian.net/browse/HHH-16986#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16986#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#100232- sha1:a133497 )