Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Using Specification with Hibernate causes Literal value issue.

$
0
0
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.

Code:

public Predicate toPredicate(Root<UserAddress> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  return cb.equal(root.<Long>get("userId"), 123L)
}

generates SQL like

Code:

select * from user_address where userId = 123
this causes issues with the database statement cache. Ideally, it should be parameterised like

Code:

select * from user_address where userId = ?
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.

Viewing all articles
Browse latest Browse all 297

Trending Articles