在Hibernate中使用LIKE%

我如何LIKE %hibernate中使用。我想LIKE %hbm.xml文件中使用SQL 。我有2个查询,我要合并为1个。

select * from PAY_GROUP_VW where CASE_SID=? AND CASE_TLE like %?%

我也试过了%?%。我使用了不带like子句的方法%,它起作用。但是%不起作用。

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query

at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:630)

at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)

at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)

at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)

q.setParameter(0, csId);

q.setParameter(1, csTle);

return q.list();

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query

at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:630)

at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)

at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)

at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)

回答:

也许user_id不是char / varchar?您必须先将带有str()的user_id转换为字符数据!

例:

SELECT *

FROM abc.def_vw a

WHERE user_id = ?

AND str(user_id) LIKE '%' || ?

以上是 在Hibernate中使用LIKE% 的全部内容, 来源链接: utcz.com/qa/404805.html

回到顶部