• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete a set of records instead iteration

 
Robert Garrido
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



I'm using Hibernate 3, and in my next query I delete a list of objects one by one; I was wondering if it's possible to optimize my delete method so I delete the complete set of objects in one shot instead iterating my list of retrieved objects.



Please consider that I'm requested to maintain an ORM style so writing a delete sentence is not an option.



Thanks a lot.



public void deleteClientOrder(final Address userAddress, final ClientID clientID) throws HibernateException {

HibernateCommand command = new HibernateCommand() {

public Object execute(Session hibernateSession) {



List<String> list = hibernateSession

.createCriteria(ClientOrder.class)

.add(eq("userAddress", userAddress))

.add(eq("clientID", clientID))

.setProjection(Projections.projectionList()

.add(Projections.property("id")))

.setCacheable(false)

.list();



for (String persistenID : list) {

ClientOrder tmp = (ClientOrder) hibernateSession.get(ClientOrder.class, persistenID);

if (tmp != null) {

hibernateSession.delete(tmp);

}

}

return null;

}

};



}
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can use DML style operations...
If that page doesn't display properly check 13.4 here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic