Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

About Hibernate and Bulk Update/Delete in HQL

  Asked By: Michael    Date: Oct 16    Category: Java    Views: 6103
  

I have a problem with execution of bulk update/delete
in hibernate,
I tried something like follwing statment

update Bill set status=1 where id > 1000

(Bill is already defined in hibernate mapping and I
can quer

I used the Query class and its executeUpdate() Method
but every time I get an exception "The statment must
begin either with from or select"

I must add this point that I used the spring's
hibernate DAO support in my application.

Did you ever encountered following error?

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Trae Thompson     Answered On: Oct 16

Do you use hibernate  3.x? Bulk operations were introduced in hibernate
3.

 
Answer #2    Answered By: Rochelle Elliott     Answered On: Oct 16

I used hibernate  3.0.5 for my application  and I used
your suggested HQL Statement
Update Bill b set  b.status=1 where b.id > 1000

But unfortunately it doesn't work! I want to emphasize
again that I use hibernate under hibnerate3's
HibernateSupport of Springframework. So I ask you to
test it really and at least attach a snip of code
(just a little that required) and then promote it as
your solution if it is possible!

 
Answer #3    Answered By: Silvia Chapman     Answered On: Oct 16

If you use hibernate  3 ,you must run following statment  as update statment:


Query query=hibernateSession.query("Update Bill b set  b.status=? where b.id > ?");
query.setInteger(1);
query.setInteger(1000);
query.list();

 
Answer #4    Answered By: Ty Thompson     Answered On: Oct 16

I have used hibernate  3.0 bulk  delete as follows and it works fine.


int deletedAttachments = session.createQuery(
"delete Attachment where fkFrmTrackingId= :trackingId and filename= :filename").
setLong("trackingId", trackingId).
setString("filename", filename).
executeUpdate();

 
Didn't find what you were looking for? Find more on About Hibernate and Bulk Update/Delete in HQL Or get search suggestion and latest updates.




Tagged: