1

I am creating a sql query through hibernate. I have a select query like;

SELECT IFNULL(DATE_FORMAT(q.create_date, '%Y-%m-%d %H:%i'), ' ') as createDate ..

but hibernate converts that query to

SELECT IFNULL(DATE_FORMAT(q.create_date, '%Y-%m-%d %H?'), ' ') as createDate

So it thinks that i need to send a parameter for question mark.

Is there any idea why this is happening ?

Thanks

likeachamp
  • 765
  • 4
  • 11
  • 21

1 Answers1

0

You have to escape the : in Hibernate.

Refer to this post - Using Hibernate query : colon gets treated as parameter / escaping colon

You can do it by changing the query to:

SELECT IFNULL(DATE_FORMAT(q.create_date, '%Y-%m-%d %H\\:%i'), ' ') as createDate ..

Update:

Alternatively, you can replace with unicode character as mentioned in this post - how to escape colon in HQL

q=q.replaceAll(":","'||unistr('\\003A')||'");

Community
  • 1
  • 1
Chaitanya
  • 15,403
  • 35
  • 96
  • 137
  • In that case, hibernate converts it as `'%Y-%m-%d %H\:%i'` and returns an error says **'Not all named parameters have been set: [%i]'** – likeachamp Nov 20 '15 at 13:39
  • This doesn't work either. It completely changes the colon with that string (`'%Y-%m-%d %H'||unistr('003A')||'%i'`) On the link provided, HQL is used. I am using SQL. That might be the problem. – likeachamp Nov 20 '15 at 14:05