Я бы хотел найти «полное совпадение слов» в 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();
}
и шаблон:
@Entity
public class Template implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="template_id")
private int templateId;
@Lob()
private String content;
@Column(name="method_id")
private byte methodId;
private String subject;
private String tags;
@Column(name="template_name")
private String templateName;
private String thumbnail;
}
Однако я получаю:
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)
, а также?не заменяется тегами.
Что не так?