-->
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: promlem with non-select Queries of HQl
PostPosted: Wed Dec 16, 2009 7:03 am 
Newbie

Joined: Fri Dec 11, 2009 6:24 am
Posts: 2
hi,
i m getting problem with delete Query Of HQL

code:
Transaction tx=ses.beginTransaction();


Query q1=ses.createQuery("delete from EmpBean as where eb.no>=? and eb.no<=:p1");

q1.setInteger(0,100);
q1.setInteger("p1",200);

int rowcount=q1.executeUpdate();
System.out.println(rowcount);
tx.commit();

Compilation Error:
can find symbol executeUpdate()

but i imported org.hibernate.cfg and org.hibernate packages and also i added jar files to the classpath....


Can you tell how to solve this error?


Top
 Profile  
 
 Post subject: Re: promlem with non-select Queries of HQl
PostPosted: Wed Dec 16, 2009 1:45 pm 
Newbie

Joined: Wed Dec 16, 2009 12:24 pm
Posts: 6
Location: Munich
I think you don't can execute deletes or updates with session.createQuery().
If you're working with Spring's HibernateTemplate you can do bulk updates.

Code:
getHibernateTemplate().bulkUpdate( "delete from EmpBean as where eb.no>=? and eb.no<=?", new Object[] {100L, 200L} );   


This is the HibernateTemplate.bulkUpdate():
Code:
   public int bulkUpdate(final String queryString, final Object[] values) throws DataAccessException {
      Integer updateCount = (Integer) executeWithNativeSession(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.createQuery(queryString);
            prepareQuery(queryObject);
            if (values != null) {
               for (int i = 0; i < values.length; i++) {
                  queryObject.setParameter(i, values[i]);
               }
            }
            return new Integer(queryObject.executeUpdate());
         }
      });
      return updateCount.intValue();
   }


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.