-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: SQL Error: 1064, SQLState: 42000
PostPosted: Sun Jul 28, 2013 10:28 am 
Newbie

Joined: Sun Jul 28, 2013 10:23 am
Posts: 4
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>


Top
 Profile  
 
 Post subject: Re: SQL Error: 1064, SQLState: 42000
PostPosted: Sun Jul 28, 2013 12:41 pm 
Newbie

Joined: Wed Mar 19, 2008 11:19 am
Posts: 15
Location: Orlando
Look at the named query. You have a comma after the last field.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.