OpenJPA appears to use a default ESCAPE character ("/"), which causes
problems when using this character as a String literal in a query.For example, in the following query: SELECT e FROM ENTITY e WHERE e.text LIKE '%\%' I am searching for the slash "\" character, but OpenJPA converts this to the following: SELECT e0.id, e0.text FROM ENTITY e0 WHERE (CAST(e0.text AS VARCHAR(1000)) LIKE ? ESCAPE '\') [params=(String) %\%] which actually searches for the percent symbol (%). When the slash appears elsewhere in a string literal in the query with other text, even more problems may occur. For example, the following exception may occur: <openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Escape character must be followed by escape character, _, or %. It cannot be followed by any other character or be at the end of the pattern. This seems like a bug since the JPA spec states: "The use of Java escape notation is not supported in query string literals" (4.6.1) and the escape notation is optionally specified by the user: "string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]" (4.6.9). I'm just looking for more thoughts on this before logging a bug, and also curious as to whether this is configurable or can be overridden in OpenJPA.
