Ruben Gehring (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6401f5e...
) *commented* on HHH-16986 (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiMzU5ZT...
)
Re: CoercionException caused by attempted coercion of query param to entity field type (
https://hibernate.atlassian.net/browse/HHH-16986?atlOrigin=eyJpIjoiMzU5ZT...
)
I’ve never worked with HIbernate directly, only ever through spring data, which is why
it’s a spring data example. But, point taken. Any new tickets I open, or follow up
examples, will have be in pure Hiberate 🙂
As for the result type being unknowable to Hibernate upon query creation time:
Half of the examples in the attached project where of the type "SELECT 2 * ?1
..." which have this issue.
But the other half are modifying queries on an entity where I’d imagine the return type of
the calculation should be known, for example the following, translated into pure Hibernate
and confirmed to throw the same exception:.
Session session = em.unwrap(Session.class);
session.createQuery("""
UPDATE TestEntity test
SET test.bigDecimalField = test.intField * ?1
""")
.setParameter(1, BigDecimal.ofValue(2.5d))
.executeUpdate();
I’d imagine that Hibernate could know that test.bigDecimalField is of type BigDecimal ,
given it’s part of the entity to be updated.
The other thing is that it seems to me that there is another thing that’s confusing me
besides Hibernate not being able to know it’s return type.
Consider the following excerpt of the above:
Query query = session.createQuery("""
UPDATE TestEntity test
SET test.bigDecimalField = test.intField * ?1
""");
When running this in debug mode and inspecting the query that is created it will have a
single positional parameter (correct) with the anticipatedType =
BasicSqmPathSource(intField : Integer). But it seems to me that test.intField is not a
parameter at all. Based on this and also the error message it seems like Hibernate is
trying to push the parameter value into the wrong operand.
I guess it might just have copied over the anticipated type of the operand it does know (
test.intField ) to the operand it does not know. And since the anticipated type contains
the name of the field that makes it seem like Hibernate is trying to assign the parameter
value to the field when in reality it is still assigned to the parameter ?1 ?
(
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 )