JPQL:将Long转换为String以执行LIKE搜索 [英] JPQL: cast Long to String to perform LIKE search
本文介绍了JPQL:将Long转换为String以执行LIKE搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下JPQL查询:
I have the following JPQL query:
SELECT il
FROM InsiderList il
WHERE ( il.deleteFlag IS NULL OR il.deleteFlag = '0' )
AND il.clientId = :clientId
AND ( LOWER( il.name ) LIKE :searchTerm
OR il.nbr LIKE :searchTerm
OR LOWER( il.type ) LIKE :searchTerm
OR LOWER( il.description ) LIKE :searchTerm )
客户希望我们能够在nbr
字段(即java.lang.Long
)中进行搜索.
The customer wants us to be able to search be the nbr
field, which is a java.lang.Long
.
Q :
如何使用JPQL在java.lang.Long
上执行LIKE搜索?
How do you perform a LIKE search on a java.lang.Long
using JPQL?
推荐答案
您可以在HQL中使用CAST
:
You can use the CAST
in HQL:
SELECT il
FROM InsiderList il
WHERE ( il.deleteFlag IS NULL OR il.deleteFlag = '0' )
AND il.clientId = :clientId
AND ( LOWER( il.name ) LIKE :searchTerm
OR CAST( il.nbr as string ) LIKE :searchTerm
OR LOWER( il.type ) LIKE :searchTerm
OR LOWER( il.description ) LIKE :searchTerm )
但是这样做可能会导致严重的性能问题,因为数据库将无法使用nbr
索引(如果对nbr
列进行了索引).
But you can have serious performance problems doing this, because the database will cannot use the nbr
index (if nbr
column is indexed).
这篇关于JPQL:将Long转换为String以执行LIKE搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文