Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I drop table using hibernate native SQL query

I am trying to drop the temp table using hibernate native SQL (createSQLQuery) statement. Here is code:

session.createSQLQuery("DROP TABLE tmp_dummy_table").executeUpdate();

However It throws me below exception:

SQL Error: 1003, SQLState: 24000
ORA-01003: no statement parsed

Exception while creating tmp_dummy_table tableorg.hibernate.exception.GenericJDBCException: org.hibernate.exception.GenericJDBCException:could not execute query
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:2223)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
        at org.hibernate.loader.Loader.list(Loader.java:2099)
        at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
        at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
        at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
        at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) ....

Could you please suggest whats wrong in this code?

like image 587
sun2 Avatar asked Nov 17 '11 18:11

sun2


People also ask

Can I use native SQL in hibernate?

You can use native SQL to express database queries if you want to utilize database-specific features such as query hints or the CONNECT keyword in Oracle. Hibernate 3.x allows you to specify handwritten SQL, including stored procedures, for all create, update, delete, and load operations.

How to create a sqlquery in hibernate?

For Hibernate Native SQL Query, we use Session.createSQLQuery (String query) to create the SQLQuery object and execute it. For example, if you want to read all the records from Employee table, we can do it through below code.

How to use the hibernate APIs for querying?

Let us see how we can use the APIs for querying. The most basic SQL query is Hibernate Native Scalar Query. In this, it fetches the list of values (which is raw data) from one or more database tables. Let us see the syntax of native Scalar (Values) queries:

What is hibernate native scalar query?

The most basic SQL query is Hibernate Native Scalar Query. In this, it fetches the list of values (which is raw data) from one or more database tables. Let us see the syntax of native Scalar (Values) queries:


Video Answer


1 Answers

From your stacktrace it looks like you called list() instead of executeUpdate(), as you write in the code sample. Make sure you actually call executeUpdate().

like image 72
axtavt Avatar answered Sep 30 '22 03:09

axtavt