Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

delete sttement in hql

  Asked By: Emily    Date: Jun 16    Category: Java    Views: 1908

int i= session.createQuery("delete from Artists where NickName
= 'ee'").executeUpate();

org.hibernate.exception.SQLGrammarException: could not execute
update query
at org.hibernate.exception.SQLStateConverter.convert
at org.hibernate.exception.JDBCExceptionHelper.convert
at org.hibernate.hql.ast.UpdateStatementExecutor.execute
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate
at org.hibernate.impl.SessionImpl.executeUpdate
at org.hibernate.impl.QueryImpl.executeUpate
at hibernateclasses.delete.main(delete.java:17)
Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]
[SQL Server]Line 1: Incorrect syntax near 'artists0_'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate
at org.hibernate.hql.ast.UpdateStatementExecutor.execute
... 4 more
Exception in thread "main"



3 Answers Found

Answer #1    Answered By: Woodrow Jones     Answered On: Jun 16

Turn on the Show SQL option of the Hibernate, so that you can see the
generated SQL query, and see what is possibly wrong with it.

Answer #2    Answered By: Iris Sanders     Answered On: Jun 16

i do not know about HQL but the problem here seem like
you use createQuery while it can be execute only like that
session.execute("delete from Artists where NickName = 'ee'")
only i think it will work fine
and there is no need for int  i

Answer #3    Answered By: Olga Allen     Answered On: Jun 16

First of all your deletion approach is important.
I mean most of the time deletion is based on PK because indexing is based on that. there is a simple solution for this, as:
Artists artist = (Artists) session.get (Artists.class, PK);

Although I don't suggest this but, all you have to do now, is to retrieve the PK of the record whose NickName
= 'ee';
Can u do that?

The better approach would be a revision in deletion which we'll talk if interested.

Didn't find what you were looking for? Find more on delete sttement in hql Or get search suggestion and latest updates.