History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HHH-2674
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Shelly McGowan
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Hibernate3

Query using Escape syntax in LIKE expression with PostgresSQL 8.2 results in PSQLException: The column index is out of range

Created: 15/Jun/07 02:52 PM   Updated: 27/Apr/08 10:10 PM
Component/s: core
Affects Version/s: 3.2.4.sp1
Fix Version/s: None

Time Tracking:
Not Specified

Environment: JBEAP RC6 - 3.2.4.SP1_CP01
Issue Links:
Relates
 


 Description  « Hide

JPQL:

createQuery(
                "select distinct Object(c) FROM Customer c, in(c.aliases) a WHERE a.alias LIKE 'sh\\_ll' escape '\\'")
                .setMaxResults(NUMOFCUSTOMERS)
                .getResultList();



HIBERNATE: select distinct customer0_.ID as ID3_, customer0_.NAME as NAME3_, customer0_.country as country3_, customer0_.code as code3_, customer0_.FK6_FOR_CUSTOMER_TABLE as FK5_3_, customer0_.FK5_FOR_CUSTOMER_TABLE as FK6_3_ from CUSTOMER_TABLE customer0_ inner join FKS_ALIAS_CUSTOMER aliases1_ on customer0_.ID=aliases1_.FK_FOR_CUSTOMER_TABLE inner join ALIAS_TABLE alias2_ on aliases1_.FK_FOR_ALIAS_TABLE=alias2_.ID where alias2_.ALIAS like 'sh\_ll' escape '\' limit ?


 ERROR: javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query
       .
       .
       .
Caused by: org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
        at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:52)
        at org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(SimpleParameterList.java:113)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc2Statement.java:2106)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.setInt(AbstractJdbc2Statement.java:1151)
        at org.hibernate.loader.Loader.bindLimitParameters(Loader.java:1646)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1566)
        at org.hibernate.loader.Loader.doQuery(Loader.java:673)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2220)


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Shelly McGowan - 31/Oct/07 07:53 AM
http://www.postgresql.org/docs/8.1/interactive/functions-matching.html
Section 9.7.1
Note that the backslash already has a special meaning in string literals, so to write a pattern constant that contains a backslash you must write two backslashes in an SQL statement. Thus, writing a pattern that actually matches a literal backslash means writing four backslashes in the statement. You can avoid this by selecting a different escape character with ESCAPE; then a backslash is not special to LIKE anymore. (But it is still special to the string literal parser, so you still need two of them.)

The above JPQL query should be written:

c = getEntityManager().createQuery(
                "select distinct Object(c) FROM Customer c, in(c.aliases) a WHERE a.alias LIKE 'sh\\\\_ll' escape '\\\\'")
                .setMaxResults(NUMOFCUSTOMERS)
                .getResultList();

resulting in:
Hibernate: select distinct customer0_.ID as ID3_, customer0_.code as code3_, customer0_.country as country3_, customer0_.FK6_FOR_CUSTOMER_TABLE as FK6_3_, customer0_.NAME as NAME3_, customer0_.FK5_FOR_CUSTOMER_TABLE as FK5_3_ from CUSTOMER_TABLE customer0_ inner join FKS_ALIAS_CUSTOMER aliases1_ on customer0_.ID=aliases1_.FK_FOR_CUSTOMER_TABLE inner join ALIAS_TABLE alias2_ on aliases1_.FK_FOR_ALIAS_TABLE=alias2_.ID where alias2_.ALIAS like 'sh\\_ll' escape '\\' limit ?