我正在编写一个查询,并希望设置参数,这是一个字符串列表。
我的查询是
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]
}
但我得到了一个例外
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.
答案 0 :(得分:1)
要绑定列表,您必须使用带有命名参数的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();