开发者

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

开发者 https://www.devze.com 2023-01-20 06:01 出处:网络
I want to change a column from a table to uppercase before using like and filtering what i开发者_运维问答s the keyword in HQL?

I want to change a column from a table to uppercase before using like and filtering what i开发者_运维问答s the keyword in HQL?

here's my query

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

Thanks


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"


I m writing a sample query in HQL:

session.createQuery(from Certificate where lower(assignedTo)=:userName)
    .setString("userName",username);

Assumptions: a table named Certificate exists with field assignedTo. session is the Hibernate Session.

0

精彩评论

暂无评论...
验证码 换一张
取 消