-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using Delete Command
PostPosted: Wed Jun 27, 2007 11:18 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
Hi,

I am fairly new to hibernate,I have a query, i am trying to delete records.
Can i directly use Delete command and use executeUpdate(), as I am trying to do

Code:
StringBuffer queryString = new StringBuffer();
queryString.append("Delete from TableDO table ");
queryString.append(" where table.createdDate < '");
queryString.append(currentDate);
queryString.append("'");


then for executing this query.. I am using this function

Code:
public List executeQuery(final String query)
      throws ServiceException {
      init();
return (List)this.hibernateTemplate.execute(new HibernateCallback() {
  public Object doInHibernate(Session session) throws HibernateException   
  {
    Query q = session.createQuery(query);
    q.executeUpdate();
   
             }
       });
      
  }

assuming that all my mapping are correctly done as i am able to insert records in this table and also update those records.

When i am trying to execute the above statement , it gives me an error :-


Code:
20:36:00,265 ERROR [JDBCExceptionReporter] ORA-00942: table or view does not exist
Caused by:
org.hibernate.exception.SQLGrammarException: could not execute query
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:2214)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
        at org.hibernate.loader.Loader.list(Loader.java:2090)
        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:150)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 5:10 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
createQuery() creates an HQL query, not an SQL one... So you shouldn't speak about table in your query. I guess that if you do here, it's because you wrote sql instead of HQL.

For SQL, use createSQLQuery(), though it's preferable to use HQL since it's an object oriented query language.

Always use object and property names, not table and column ones.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.