JPA @NamedQuery with bitwise AND (&) as criteria

前端 未结 2 358
半阙折子戏
半阙折子戏 2021-01-15 02:26

does anyone know how to use bitwise AND (&) as criteria for a JPA NamedQuery without having to use a @NamedNativeQuery?

I\'m storing status bits in a field.

相关标签:
2条回答
  • 2021-01-15 02:37

    Bitwise AND is not part of JPQL. But...

    Can be use 2 rules:

    1. division by 2^х will shift the bits right by x (exemple 1011010/1000=1011)
    2. z mod 2 = 1 if right bit is 1 (exemple 1011 mod 2 = 1)

    try

    SELECT v FROM ViewProductsList v WHERE MOD(v.statusId/16 , 2) = 1
    
    0 讨论(0)
  • 2021-01-15 02:48

    'Bitwise AND' is not part of JPQL. Native query is the portable way to go.

    0 讨论(0)
提交回复
热议问题