title: Using a named native sql query using xml mapping error
body: <p>I'm using a named native SQL query using xml mapping, I need to use the mysql function AES_ENCRYPT and AES_DECRYPT but marked me syntax error but do not understand why. Now review it all and is well</p>
  
  <p><strong>I'm using a blob field to store the encrypted data of AES_ENCRYPT</strong></p>
  
  <p><strong>Usuario.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 14/12/2013 03:41:41 AM by Hibernate Tools 3.6.0 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="Model.TO.Usuario" table="usuario" catalog="sintaxhighlighter"&gt;
          &lt;id name="correo" type="string"&gt;
              &lt;column name="Correo" length="50" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="roles" class="Model.TO.Roles" fetch="select"&gt;
              &lt;column name="Roles_idRoles" length="2" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;property name="password" type="java.lang.String"&gt;
              &lt;column name="Password"  not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="nombres" type="string"&gt;
              &lt;column name="Nombres" length="50" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="apellidoP" type="string"&gt;
              &lt;column name="ApellidoP" length="25" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="apellidoM" type="string"&gt;
              &lt;column name="ApellidoM" length="25" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;set name="codigoses" table="usuarios_has_codigos" inverse="false" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="Usuarios_Correo" length="50" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;many-to-many entity-name="Model.TO.Codigos"&gt;
                  &lt;column name="Codigos_CodName" length="4" not-null="true" /&gt;
              &lt;/many-to-many&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  
         &lt;sql-query name="finByCorreo" &gt;
          &lt;return alias="Usuario" class="Model.TO.Usuario" /&gt;
          SELECT use.Correo AS {Usuario.correo},  
          AES_DECRYPT (use.Password,'escom') AS {Usuario.password},
          use.Nombres AS {Usuario.nombres}, 
          use.ApellidoP AS {Usuario.apellidoP}, 
          use.ApellidoM AS {Usuario.apellidoM}     
          FROM usuario use
          WHERE use.Correo LIKE :tags
      &lt;/sql-query&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>FindByCorreo</strong></p>
  
  <pre><code>public Usuario finByCorreo(Usuario usuario) {
          Usuario model = null;
          Session session = HibernateUtil.getSessionFactory().openSession();
          System.out.println(usuario.getPassword() + " " + usuario.getCorreo());
  
          try {
              session.beginTransaction();
              Query query=session.getNamedQuery("finByCorreo");
  
              query.setString("tags", usuario.getCorreo());
              model = (Usuario) query.uniqueResult();
              session.getTransaction().commit();
          } catch (HibernateException e) {
              System.out.println(e.getMessage());
              session.getTransaction().rollback();
          }
          return model;
      }
  </code></pre>
  
  <p><strong>Usuario.java</strong></p>
  
  <pre><code>public class Usuario  implements java.io.Serializable {
       private String correo;
       private Roles roles;
       private String password;
       private String nombres;
       private String apellidoP;
       private String apellidoM;
       private Set codigoses = new HashSet(0);
       .
   }
  </code></pre>
  
  <p>resulting error</p>
  
  <pre><code>WARN: SQL Error: 1064, SQLState: 42000
  dic 14, 2013 11:13:14 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE use.Correo LIKE 'amezcua92@hotmail.com'' at line 7
  </code></pre>