1

I have a HQL query that uses data across several tables to pull in a list of objects. Part of the query requires case-sensitive comparison, but the default collation on the database is case insensitive.

I know that I can convert the query to SQL I can solve the issue by specifying collate utf8_bin (I am targeting a MySql database), but this would require a more complicated query (from a code comprehension and maintenance perspective) so I'd like to avoid the SQL option if possible.

Unfortunately, HQL does not include the collate token.

Is there a way to insert pieces of SQL in a HQL query?

David Mason
  • 2,917
  • 4
  • 30
  • 45
  • Maybe this [SO question/answer](http://stackoverflow.com/questions/1538577/mix-hql-and-sql-in-the-same-query) can help you – Yaroslav Oct 22 '12 at 07:02

1 Answers1

0

You can try something like below

@Column(name = "uuid", columnDefinition = "varchar(23) COLLATE utf8_bin")

reference: https://forum.hibernate.org/viewtopic.php?f=9&t=998806&view=next

Ravi K
  • 976
  • 7
  • 9
  • 1
    That will set the collation for the column permanently, which is not desired in this case - I just want to use a different collation during a single query without changing it for the column. – David Mason Oct 23 '12 at 23:07
  • Ohh ok. Can you try putting collate clause directly in HQL i.e. put rest of the query in HQL & put collate clause like SLQ in that query. I never tried this, but since as per aboce exampel, collate is allowed in column then it should work fine in query also. May be HQL will keep collate clause as it is without changing it. GIve it a try. – Ravi K Oct 25 '12 at 06:19
  • an even if you need it permanently, it seem if the DB is already created with a different collation this will not override the db settings. – рüффп Sep 17 '21 at 12:06