aspose file tools
The moose likes Object Relational Mapping and the fly likes Batch Delete in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Batch Delete in Hibernate" Watch "Batch Delete in Hibernate" New topic
Author

Batch Delete in Hibernate

Saket Barve
Ranch Hand

Joined: Dec 19, 2002
Posts: 223
I did some groundwork on batch deletes in Hibernate and came across a useful link at Aaron Johnson's blog.

I implemented the suggestion in the following manner:



Upon implementing the given suggestion as shown above, following MappingException results:



It appears that the session's delete method is not able to make sense of the query passed as a string.

Can anyone tell me what I am doing wrong? Or, is there is another way to go about this mass delete thing?

Thanks,
Saket
[ May 13, 2007: Message edited by: Saket Barve ]
Jaikiran Pai
Saloon Keeper

Joined: Jul 20, 2005
Posts: 6718

The Hibernate documentation mentions that this method has been deprecated.

Deprecated. consider using HQL delete statements

Delete all objects returned by the query. Return the number of objects deleted.

Note that this is very different from the delete-statement support added in HQL since 3.1. The functionality here is to actually peform the query and then iterate the results calling Session.delete(Object) individually.


Moreover, this method is available on org.hibernate.classic.Session object and not org.hibernate.Session


[My Blog] [JavaRanch Journal]
Saket Barve
Ranch Hand

Joined: Dec 19, 2002
Posts: 223
Thanks, Jaikiran.

The solution was to modify the delete query and pass the ID's as a parameter-list.
 
IntelliJ Java IDE
 
subject: Batch Delete in Hibernate
 
Threads others viewed
session.delete() is throwing exception
IllegalArgumentException: Removing a detached instance
Error Deleting Persisted Objects: Hibernate/MySQL
Hibernate - Can't delete from database!
Batch Delete Problem
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture