-->
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.  [ 8 posts ] 
Author Message
 Post subject: Help me,where is error?serval days can not solve!!
PostPosted: Wed Dec 21, 2005 1:07 am 
Newbie

Joined: Mon Dec 19, 2005 3:59 am
Posts: 3
I use Hibernate 3.1 , mysql 4.0
==========
part code:
List articles = new ArrayList();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("from EventAttachDto");
q.setFirstResult(1);
q.setMaxResults(10);
articles = q.list();
tx.commit();
session.close();
==================
throw Exception:
2005-12-19 14:54:12,060 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [select eventattac0_.id as id0_, eventattac0_.event_id as event2_0_, eventattac0_.attach_title as attach3_0_, eventattac0_.creater as creater0_, eventattac0_.attach_time as attach5_0_, eventattac0_.attach_status as attach6_0_, eventattac0_.attach_remarks as attach7_0_ from events_attach eventattac0_]
java.sql.SQLException: 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 '?, ?' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
2005-12-19 14:54:12,060 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000
2005-12-19 14:54:12,060 ERROR [org.hibernate.util.JDBCExceptionReporter] 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 '?, ?' at line 1
2005-12-19 14:54:12,070 DEBUG [org.hibernate.jdbc.JDBCContext] after autocommit
2005-12-19 14:54:12,070 INFO [STDOUT] from EventAttachDto
2005-12-19 14:54:12,070 INFO [STDOUT] org.hibernate.exception.SQLGrammarException: could not execute query


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 1:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You need to show the class and mapping file.
In anycase, you can cut and paste the SQL into MySQL console and workout from there where the error is thus you will be able to correct the appropriate mapping.


Top
 Profile  
 
 Post subject: I have class&mapping file.bellow:
PostPosted: Wed Dec 21, 2005 1:28 am 
Newbie

Joined: Mon Dec 19, 2005 3:59 am
Posts: 3
package com.bp.dto;

import java.io.*;
import java.sql.*;

public class EventAttachDto implements Serializable {
private Integer id;
private Integer event_id;
private String attach_title;
private Integer creater;
private Timestamp attach_time;
private byte attach_status;
private String attach_remarks;
public Integer getId() {
return id;
}

public Integer getEvent_id() {
return event_id;
}

public String getAttach_title() {
return attach_title;
}

public Integer getCreater() {
return creater;
}

public Timestamp getAttach_time() {
return attach_time;
}

public byte getAttach_status() {
return attach_status;
}

public String getAttach_remarks() {
return attach_remarks;
}

public void setId(Integer id) {
this.id = id;
}

public void setEvent_id(Integer event_id) {
this.event_id = event_id;
}

public void setAttach_title(String attach_title) {
this.attach_title = attach_title;
}

public void setCreater(Integer creater) {
this.creater = creater;
}

public void setAttach_time(Timestamp attach_time) {
this.attach_time = attach_time;
}

public void setAttach_status(byte attach_status) {
this.attach_status = attach_status;
}

public void setAttach_remarks(String attach_remarks) {
this.attach_remarks = attach_remarks;
}

}
==========================
EventAttach.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.bp.dto">
<class name="EventAttachDto" table="events_attach">
<comment>event_attach elements.</comment>
<id name="id" type="integer">
<generator class="increment"/>
</id>
<property name="event_id" column="event_id" type="integer" not-null="true"/>
<property name="attach_title" column="attach_title" type="string" not-null="true"/>
<property name="creater" column="creater" type="integer" not-null="true"/>
<property name="attach_time" column="attach_time" type="timestamp" not-null="true"/>
<property name="attach_status" column="attach_status" type="byte" not-null="true"/>
<property name="attach_remarks" column="attach_remarks" type="string" not-null="true"/>
</class>
</hibernate-mapping>
==========================
hibernate.cfg.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bpcrm_</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="connection.username">superlin</property>
<property name="connection.password">1234</property>
<property name="cglib.use_reflection_optimizer">false</property>
<mapping resource="hbm/EventAttach.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: I use hibernate can run insert operation
PostPosted: Wed Dec 21, 2005 1:30 am 
Newbie

Joined: Mon Dec 19, 2005 3:59 am
Posts: 3
I use hibernate can run insert operation


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 1:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Well, it looks fine to me. Does the SQL work when cut and pasted into the MySQL console? Maybe it will give you more information. I would also double check my JDBC driver and try another version of it... you just never know.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 6:43 am 
Newbie

Joined: Mon Oct 24, 2005 2:51 pm
Posts: 7
Quote:
throw Exception:
2005-12-19 14:54:12,060 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [select eventattac0_.id as id0_, eventattac0_.event_id as event2_0_, eventattac0_.attach_title as attach3_0_, eventattac0_.creater as creater0_, eventattac0_.attach_time as attach5_0_, eventattac0_.attach_status as attach6_0_, eventattac0_.attach_remarks as attach7_0_ from events_attach eventattac0_]
java.sql.SQLException: 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 '?, ?' at line 1

The SQL in the quote is not the SQL that generated the error. The error is close to some query parameters, but the SQL is missing any conditional statements. There should be a where clause because you are restricting the result set size. Please show a more complete stacktrace.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 6:46 am 
Newbie

Joined: Mon Oct 24, 2005 2:51 pm
Posts: 7
Quote:
throw Exception:
2005-12-19 14:54:12,060 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [select eventattac0_.id as id0_, eventattac0_.event_id as event2_0_, eventattac0_.attach_title as attach3_0_, eventattac0_.creater as creater0_, eventattac0_.attach_time as attach5_0_, eventattac0_.attach_status as attach6_0_, eventattac0_.attach_remarks as attach7_0_ from events_attach eventattac0_]
java.sql.SQLException: 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 '?, ?' at line 1

The SQL in the quote is not the SQL that generated the error. The error is close to some query parameters, but the SQL is missing any conditional statements. There should be a where clause because you are restricting the result set size. Please show a more complete stacktrace.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 2:06 pm 
Newbie

Joined: Tue Oct 25, 2005 6:11 am
Posts: 5
Location: Hamburg, Germany
I had a similar problem. The sql-output from hibernate was no problem for mysql, when copied it and filled the '?' with the correct values and run the statement directly against the database.
But my application threw an SQLGrammarException.
After an update of mysql-connector from 3.1.6 to 3.1.11 everything works fine!

I hope this helps you as well.
Merry chistmas.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.