title: Restrictions.sqlRestriction Parameter index out of range
body: <p>I would like to Search for “whole word match” in MySQL and Hibernate.</p>
  
  <p>My code is:</p>
  
  <pre><code>public Collection&lt;Template&gt; findByOneTag(String tags) {
      // since the tags are in , format we will replace it with |
      return getSession().createCriteria(Template.class)
              .add(Restrictions.sqlRestriction("tags REGEXP '[[:&lt;:]]?[[:&gt;:]]'", tags.replaceAll(",", "|"), StandardBasicTypes.STRING)).list();
  }
  </code></pre>
  
  <p>and Template:</p>
  
  <pre><code>    @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;
  }
  </code></pre>
  
  <p>However I get:</p>
  
  <pre><code>Caused by: java.sql.SQLException: Parameter index out of range (1 &gt; 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)
  </code></pre>
  
  <p>as well as the ? is not being replaced with tags.</p>
  
  <p>What is wrong?</p>