Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change to case of a column to Upper in HQL Hibernate

Tags:

hibernate

hql

I want to change a column from a table to uppercase before using like and filtering what is the keyword in HQL?

here's my query

SELECT abc
FROM ABC abc
WHERE abc.id = ?
And upper(abc.description) like '%?%'

Thanks

like image 723
Gauls Avatar asked Oct 15 '10 08:10

Gauls


People also ask

Can we use case in HQL?

yes case is working in HQL now (I am using 3.5.

Is HQL case sensitive?

HQL queries are case insensitive; however, the names of Java classes and properties are case-sensitive HQL is used to execute queries against database.

Can we use select * in HQL?

Keywords like SELECT, FROM, and WHERE, etc., are not case sensitive, but properties like table and column names are case sensitive in HQL.

Does HQL support order by?

In HQL we perform order by and group by for the given property of entity or associated entities.


1 Answers

HQL supports the upper() function defined by the EJB 3.0 specification in the SELECT and WHERE clauses. From the documentation:

14.10. Expressions

  • ...
  • Any function or operator defined by EJB-QL 3.0: substring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length(), mod()
  • ...

So the following should work:

from DomesticCat cat where upper(cat.name) like 'FRI%'

References

  • Hibernate Core Reference Guide
    • 14.10. Expressions
  • JPA 1.0 Specification
    • Section 4.6.16.1 "String Functions"
like image 140
Pascal Thivent Avatar answered Oct 04 '22 14:10

Pascal Thivent