how delete all rows with no SQL
Asked Answered
R

1

7

Is the any other way to delete all rows of a database table without writing an SQL delete statement?

List<Item> items = Ebean.find(Item.class).findList();
Ebean.delete(items);

Is there anything like

Ebean.deleteAll(Item.class)

in Ebean API?

Roland answered 14/5, 2014 at 7:16 Comment(2)
But if even if you're using EBean, you can't get much simpler/much more efficient than a rawSql "delete from mytable" or "truncate myTable". IMHO...Repertoire
What I usually do if methods are lacking is I create a MyEbean utility class and put all the methods I find lacking in there.Layne
M
-1

Indeed it exists, check this out

Delete all the beans from a Collection.

public static int delete(Collection<?> c)
                  throws javax.persistence.OptimisticLockException
Mothy answered 14/5, 2014 at 7:24 Comment(2)
I can't get the link to load; does this actually delete the records from the DB, or just the entities in the model?Zanze
accidentally posted above comment as an answer earlier today. It was meant as a comment for @MothyZanze

© 2022 - 2024 — McMap. All rights reserved.