Announcement Announcement Module
Collapse
No announcement yet.
Using Specification with Hibernate causes Literal value issue. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Specification with Hibernate causes Literal value issue.

    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.
Working...
X