We've noticed an issue when using the Specification object with Hibernate when comparing Numeric type values.
The SQL generated contains literal values instead of being parameterised. e.g.
generates SQL like
this causes issues with the database statement cache. Ideally, it should be parameterised like
When using Hibernate directly, we have access to the generated TypedQuery so can force it to use a ParameterExpression and then set the parameter value on the TypedQuery. However, the framework generates the
TypedQuery after the Specification has set the Predicate, so this work around isn't possible.
Has anyone else noticed this issue? Is there a workaround for this?
Cheers,
Matt.
The SQL generated contains literal values instead of being parameterised. e.g.
Code:
public Predicate toPredicate(Root<UserAddress> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
return cb.equal(root.<Long>get("userId"), 123L)
}
Code:
select * from user_address where userId = 123
Code:
select * from user_address where userId = ?
TypedQuery after the Specification has set the Predicate, so this work around isn't possible.
Has anyone else noticed this issue? Is there a workaround for this?
Cheers,
Matt.