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:
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? |