Why Hibernate inlines Integer parameter list passed to JPA Criteria Query?

前端 未结 4 681
南方客
南方客 2020-12-16 15:12

I am building a query using JPA Criteria API. When I created two restriction predicates using javax.persistence.criteria.Path#in(Collection) method the

4条回答
  •  清歌不尽
    2020-12-16 15:52

    In issue HHH-9576 a new parameter was added to fix this issue, applicable since version 5.2.12 (?)

    
    

    If you use this parameter you don't need the verbose solution proposed by Pace anymore.

    From hibernate documentation of literal_handling_mode:

    This enum defines how literals are handled by JPA Criteria. By default (AUTO), Criteria queries uses bind parameters for any literal that is not a numeric value. However, to increase the likelihood of JDBC statement caching, you might want to use bind parameters for numeric values too. The BIND mode will use bind variables for any literal value. The INLINE mode will inline literal values as-is. To prevent SQL injection, never use INLINE with String variables. Always use constants with the INLINE mode.

提交回复
热议问题