Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

delete sttement in hql

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


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
(SQLStateConverter.java:59)
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 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
(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute
(JdbcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate
(JdbcOdbcPreparedStatement.java:136)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute
(UpdateStatementExecutor.java:67)
... 4 more
Exception in thread "main"

Share: 

 

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);
session.delete(artist);

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.




Tagged: