I the error when run a test on local machine, I have no key words, quite frastruted Using MySql 5.1
==error log=====
Hibernate: SELECT u.ID AS id1_0_0_, u.USERNAME AS username2_0_0_, u.AGE AS age3_0_0_, FROM USERXY u 2013-7-28 22:21:14 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1064, SQLState: 42000 2013-7-28 22:21:14 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 'FROM USERXY u' at line 5
===code calling the namedquery
public List<UserEntity> listUserEntity(){ try{ System.out.println("listUserEntity"); session = HibernateUtil.getSessionFactory().openSession(); Query query = session.getNamedQuery("getUserList"); return query.list(); }finally{ if(null != session){ session.close(); } } }
======mapping file==== <?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"> <hibernate-mapping package="com.tea.javatraining.strutshb.entity"> <class name="UserEntity" table="userxy"> <id name="id" type="java.lang.Long"> <column name="id" /> <generator class="native" /> </id> <property name="userName" type="java.lang.String"> <column name="username" length="20" not-null="true" unique="true" /> </property> <property name="age" type="java.lang.String"> <column name="`age`" /> </property> </class> <sql-query name="getUserList"> <return alias="user" class="com.tea.javatraining.strutshb.entity.UserEntity"/> SELECT u.ID AS {user.id}, u.USERNAME AS {user.userName}, u.AGE AS {user.age}, FROM USERXY u </sql-query> </hibernate-mapping>
====hibernate config=== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <mapping resource="com/tea/javatraining/strutshb/entity/UserEntity.hbm.xml" /> </session-factory> </hibernate-configuration>
|