1
xml 매핑을 사용하여 네이티브 원시 SQL 쿼리를 사용하고 있는데 mysql 함수 AES_ENCRYPT 및 AES_DECRYPT를 사용해야하지만 구문 오류가 표시되었지만 이유를 이해하지 못했습니다. 이제 모든 것을 검토하고 잘xml 매핑 오류를 사용하여 명명 된 네이티브 SQL 쿼리 사용
내가<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 14/12/2013 03:41:41 AM by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
<class name="Model.TO.Usuario" table="usuario" catalog="sintaxhighlighter">
<id name="correo" type="string">
<column name="Correo" length="50" />
<generator class="assigned" />
</id>
<many-to-one name="roles" class="Model.TO.Roles" fetch="select">
<column name="Roles_idRoles" length="2" not-null="true" />
</many-to-one>
<property name="password" type="java.lang.String">
<column name="Password" not-null="true" />
</property>
<property name="nombres" type="string">
<column name="Nombres" length="50" not-null="true" />
</property>
<property name="apellidoP" type="string">
<column name="ApellidoP" length="25" not-null="true" />
</property>
<property name="apellidoM" type="string">
<column name="ApellidoM" length="25" not-null="true" />
</property>
<set name="codigoses" table="usuarios_has_codigos" inverse="false" lazy="true" fetch="select">
<key>
<column name="Usuarios_Correo" length="50" not-null="true" />
</key>
<many-to-many entity-name="Model.TO.Codigos">
<column name="Codigos_CodName" length="4" not-null="true" />
</many-to-many>
</set>
</class>
<sql-query name="finByCorreo" >
<return alias="Usuario" class="Model.TO.Usuario" />
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
</sql-query>
</hibernate-mapping>
FindByCorreo
Usuario.hbm.xml AES_ENCRYPT의 암호화 된 데이터를 저장하는 BLOB 필드를 사용하고
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; }
Usuario.java
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);
.
}
결과 오류 내가 거기에 볼
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 '[email protected]'' at line 7
원한다면 고맙겠습니다.이 오류는 키워드를 고려하지 않은 경우에 발생합니다. – adan