In JPA, when executing a native query, I have to escape backslash characters to double backslash. E.g. when having a where clause like
UPPER(app.NAME) like UPPER(?) escape '\'
then I need to create a string which contains:
UPPER(app.NAME) like UPPER(?) escape '\\'
Then I run a native query using openJPA 2.2.2:
final EntityManager entityManager = EntityManagerFinder.getEntityManager();
final Query query = entityManager.createNativeQuery(sql, Response.class);
The SQL statement is read from XML file, hence Java escaping is not done here. Furthermore I verified during debugging that the String in Java is really the same as in the XML file.
Why is JPA expecting double backslash for native queries? Is this a bug in openJPA?