Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape character in JPQL

Tags:

jpa

jpql

In JPQL what is escape character we can use to escape characters such as "'"?

Ex : I am doing something like

...where person.name='Andy'

Here it is working fine

but when the person's name is Andy's then the where clause becomes like

...where person.name='Andy's'

and it returns an error saying

like image 756
Programmer Avatar asked Dec 27 '22 03:12

Programmer


1 Answers

It cannot figure out where string literal ends. Solution is nicely told in specification:

A string literal that includes a single quote is represented by two single quotes—for example: ‘literal’’s’.

In your case means:

...where person.name='Andy''s'
like image 159
Mikko Maunu Avatar answered Feb 06 '23 19:02

Mikko Maunu