Ruben Gehring (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6401f5e...
) *commented* on HHH-16986 (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiOTQyYW...
)
Re: CoercionException caused by attempted coercion of query param to entity field type (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiOTQyYW...
)
Two more points:
* Ideally the type of a parameter would depend on the parameter only, that is be
independent of the result type.
In cases where the result is based on a calculation it should be possible to pass in all
kinds of types for the operands. For example passing 2.5d and 2f to a calculation expected
to return Integer seems fine to me, and I would expect the result of (int) (2.5d * 2f) to
be 5.
* Hibernate is usually really good at this, too! It only seems to fail when I use an
entity field in the calculation (which I wish I didn’t have to but that’s another
discussion)
Consider the following almost-identical queries:
// Let test.intField be initialized to 2, int
session.createQuery("""
UPDATE TestEntity test
SET test.bigDecimalField = test.intField * ?1
""")
.setParameter(1, BigDecimal.valueOf(2.5d))
.executeUpdate();
// Result: Parameter value [2.5] did not match expected type [BasicSqmPathSource(intField
: Integer ) ]
// Let passing same value (2, int ) as a query param instead of reading the entity field
session.createQuery("""
UPDATE TestEntity test
SET test.bigDecimalField = ?1 * ?2
""")
.setParameter(1, 2)
.setParameter(2, BigDecimal.valueOf(2.5d))
.executeUpdate();
// Result: Update successful, value of 5.00 confirmed in entity
(
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#100233- sha1:f5b6255 )