-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL Delete Error
PostPosted: Fri Apr 11, 2008 1:12 pm 
Newbie

Joined: Fri Apr 11, 2008 1:06 pm
Posts: 2
Hibernate version:
3.2.6

Mapping documents:
<class name="edu.xx.org.keys.Series" table="series">
<id name="seriesId" column="series_id">
<generator class="increment"/>
</id>

<property name="seriesName" column="series_name"/>
<property name="roomName" column="room_name"/>
<set name="keys" table="keys_series" inverse="true">
<key column="series_id" />
<many-to-many column="key_id" class="edu.xx.org.keys.Key" />
</set>
</class>

Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
String hql = "delete Series series where id = :id";
System.out.println(hql);
Query q = session.createQuery(hql);
q.setInteger( "id", seriesId );
int rowCount = q.executeUpate();
tx.commit();

Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:76)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:294)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:808)
at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:89)
at edu.vt.fralin.keys.KeyManager.deleteSeries(KeyManager.java:85)
at edu.vt.fralin.keys.testGetSeries.main(testGetSeries.java:12)
Caused by: java.sql.SQLException: Syntax error or access violation message from server: "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 (name=90)' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:67)
... 5 more


Name and version of the database you are using:
Mysql 5.0.22

The generated SQL (show_sql=true):
delete from series series0_ where (name=90)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 2:28 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Try

Code:
q.setParameter( "id", seriesId );


instead of


Quote:
q.setInteger( "id", seriesId );


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 3:05 pm 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Yes q.setParameter is the one that you should use. It binds a value to the query. refer http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Query.html

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 12:54 pm 
Newbie

Joined: Fri Apr 11, 2008 1:06 pm
Posts: 2
I tried:
Code:
q.setParameter("id", seriesId);

but I am getting the following error:

org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:76)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:294)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:808)
at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:89)
at edu.vt.fralin.keys.KeyManager.deleteSeries(KeyManager.java:85)
at edu.vt.fralin.keys.testGetSeries.main(testGetSeries.java:12)

Caused by: java.sql.SQLException: Syntax error or access violation message from server: "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 (id=9)' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:67)
Code:


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