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.  [ 11 posts ] 
Author Message
 Post subject: Delete Query did not work on mysql4.0.12
PostPosted: Sat Nov 18, 2006 9:56 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
Hi ,
I am learning hibernate and tried to execute a delete query. The system said error in my query.
Please help me on what I am doing wrong.
I am using hibernate 3.1 JDK 1.3 Mysql 4.0

Error message :
ERROR JDBCExceptionReporter:58 - 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 'myclass0_ where (myclass0_.bookid='10')' at line 1"

My Code:
String deletequery="delete from MyClass a where a.bookid=:book ";
Query q=session.createQuery(deletequery);
q.setString("book","10");
q.executeUpate();
tx.commit();
hsqlCleanup(session);
HibernateUtil.closeSession();

Please help. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 18, 2006 11:48 am 
Newbie

Joined: Fri Nov 17, 2006 5:18 pm
Posts: 4
Location: Quilmes, Argentina
What dialect are you using?
The column bookid is varchar?


Top
 Profile  
 
 Post subject: Delete Query did not work on mysql4.0.12
PostPosted: Sun Nov 19, 2006 9:03 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
The dialect is org.hibernate.dialect.MySQLDialect

The column is of type Char(4)

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 9:15 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Turn on show_sql=true and then try running the sql directly in mysql.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 9:22 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
The show_sql is set to true.

The problem is it does not go to that step of showing the query in console. It just gives the error I mentioned in my posting.

Is my query correct?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 9:27 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
Ok...Here is the query in my console after I executed the same


Hibernate: delete from books myclass0_ where (myclass0_.bookid=?)

08:23:41,328 WARN JDBCExceptionReporter:57 - SQL Error: 1064, SQLState: 42000

org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70).......


I am not sure what I am doing wrong. My Select and Insert statements are working fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 10:03 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
I understood my query is showing as
delete from books myclass0_ where (myclass0_.bookid=?)
in the console.

Why is my query not translating correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 12:49 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Okay, turns out that you cant use aliases in a delete statement

delete from books a where a.bookid = "1" fails
whereas
delete from books where bookid = "1" succeeds.

Remove the alias from your HQL


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 9:38 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
Hi can you post your entire code used to delete.

I am not able to delete still. It gives query as wrong.

I did not use the alias name. books is my getter/setter class name.


Please post a sample code to delete from mysql database.Fyi I am using JDK1.3I


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 9:50 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Code:
delete from MyClass where bookid=:book


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 10:22 am 
Newbie

Joined: Sat Nov 18, 2006 9:49 am
Posts: 10
Thanks. It does not work. I noticed that I am doing
.executeUpate instead of .executeUpdate.

So I downloaded the latest release from Nov 16 and the hibernate3.jar gives unsupported version error. I assume I cannot use the new jar file in my project anymore.


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