Java Restrictions.sqlRestriction参数索引超出范围

Java Restrictions.sqlRestriction参数索引超出范围,java,mysql,hibernate,Java,Mysql,Hibernate,我想在MySQL和Hibernate中搜索“全词匹配” 我的代码是: public Collection<Template> findByOneTag(String tags) { // since the tags are in , format we will replace it with | return getSession().createCriteria(Template.class) .add(Restrictions.sqlR

我想在MySQL和Hibernate中搜索“全词匹配”

我的代码是:

public Collection<Template> findByOneTag(String tags) {
    // since the tags are in , format we will replace it with |
    return getSession().createCriteria(Template.class)
            .add(Restrictions.sqlRestriction("tags REGEXP '[[:<:]]?[[:>:]]'", tags.replaceAll(",", "|"), StandardBasicTypes.STRING)).list();
}
然而,我得到:

Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3729)
还有那个?未被标记替换


怎么了?

尝试使用以下限制:

"tags REGEXP ?"
并将以下值作为参数传递:

"[[:<:]]" + yourOriginalParameter + "[[:>:]]"
“[[::]]”
"[[:<:]]" + yourOriginalParameter + "[[:>:]]"