gpt4 book ai didi

java - Hibernate 替换字符串条件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:01 29 4
gpt4 key购买 nike

我在创建查询时遇到了一些麻烦,其中必要条件是在我需要替换特殊字符的字段中使用 like。像这样:

public List<MyClass> search(Myclass object){

Criteria cri = criteria(MyClass.class);
if(object.getName() != null){
cri.add(Restrictions.sqlRestriction("replace("+cri.getAlias()+".name,"+object.getSpecialCharacter()+", '') like '"+object.getName()+"'"));
}
if(dominio.getType()!= null){
cri.add(Restrictions.eq("type", object.getType()));
}
if(dominio.getWorkspace() != null){
cri.add(Restrictions.eq("workspace", object.getWorkspace()));
}
if(dominio.getStatus() != null){
cri.add(Restrictions.eq("status", object.getStatus()));
}

return cri.list();

}

使用这段代码我得到了以下错误:

this_.ID_MYCLASS as ID_MYCLASS1_33_0_,
this_.NM_MYCLASS as NM_MYCLASS4_33_0_,
this_.ID_STATUS as ID_STATU5_33_0_,
this_.ID_TYPE as ID_TYPE_7_33_0_,
this_.ID_WORKSPACE as ID_WORKS8_33_0_
from KDTB_MYCLASS this_
where replace(this.name,'_', '') like 'COD'
and this_.ID_WORKSPACE=?

ORA-00904: "THIS"."NAME": 无效标识符

我做错了什么?

提前致谢!

最佳答案

试试这个:

cri.add(Restrictions.sqlRestriction("replace({alias}.name,"+object.getSpecialCharacter()+", '') like '"+object.getName()+"'"));

关于java - Hibernate 替换字符串条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24440820/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com