JPQL LIKE expression to enumerate

Can JPQL execute LIKE expressions on enumerations?

If I have a Foo entity with an enum field strip, I can do the following in MySQL (the string is stored as a MySQL enumeration) ...

SELECT * FROM Foo WHERE `bar` LIKE '%SUFFIX'

However, the corresponding query in JPQL ...

SELECT f FROM Foo f WHERE f.bar LIKE '%SUFFIX'

... complains that ...

Parameter value [%SUFFIX] was not matching type [com.example.Foo$EnumType] 
+3
source share
2 answers

I do not think this is possible, the left side LIKEshould be a string_ expression (in standard JPA). From the specification:

4.6.9 Similar expressions

The syntax for using the comparison operator [NOT] LIKE in a conditional expression is as follows:

string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]

. pattern_value , (_) , (%) ( ) . escape_character - (.. char Character) , pattern_value.

enum_expression .

( ):

SELECT f 
  FROM Foo f 
 WHERE f.bar = com.acme.Bar.SOME_CONSTANT 
    OR f.bar = com.acme.Bar.SOME_OTHER_CONSTANT

- bar String ( getter/setter).

  • JPA 1.0
    • 4.6.9 " "
    • 4.14 "BNF"
+6

JPA ?

EclipseLink 2.1.

, varchar SQL, .

+1

Source: https://habr.com/ru/post/1763805/


All Articles