我正在编写一个查询并想设置一个字符串列表的参数。
我的查询是
def strQuery = """SELECT * from user u where u.status in (?)"""
def session = sessionFactory.getCurrentSession()
def resultList = session.createSQLQuery(strQuery)
.setParameter(0, UserStatus.List)
.list();
在哪里
public enum UserStatus {
ACTIVE("Active"),
ARCHIVE("Archived"),
public static final List<UserStatus> List = [ACTIVE,ARCHIVED]
}
但我遇到了一个异常(exception)
ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: operator does not exist: character varying = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
最佳答案
要绑定(bind)列表,您必须使用 setParameterList带命名参数。setParameter
仅适用于单个值。
def strQuery = """SELECT * from user u where u.status in (:statusList)"""
def session = sessionFactory.getCurrentSession()
def resultList = session.createSQLQuery(strQuery)
.setParameterList('statusList', UserStatus.List)
.list();
关于grails - 如何将列表作为参数添加到grails中的sqlQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24669695/