Incorrect use of the STR () function in HQL

With this HQL query:

SELECT DISTINCT fs FROM FileStatus fs WHERE UPPER(STR(fs.filePath)) LIKE :FILE_PATH

I get:

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)

and with my named parameter FILE_PATH, the map has the following:

paramMap.put("FILE_PATH", "%PATHNAME%");

I have no idea why this is happening. To make things more confusing (or maybe this will help everyone), if I use a number in the file path, for example paramMap.put("FILE_PATH", "%23%");, it works fine.

The parameter map is passed to the DAO.read () method along with the request. Hibernate handles everything else. Something like that:

fileStatusDao.read(query, parameterMap);

Thanks in advance for your help.

+3
source share
1 answer

The problem ended up using the STR () function for an attribute that was already a string.

0
source

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


All Articles