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?

tok
  • 909
  • 1
  • 10
  • 21
  • But if even if you're using [EBean](http://www.avaje.org/ebean/introquery_rawsql.html), you can't get much simpler/much more efficient than a rawSql "delete from mytable" or "truncate myTable". IMHO... – FoggyDay May 14 '14 at 07:28
  • 1
    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. – Erwin Smout May 14 '14 at 07:28

1 Answers1

-1

Indeed it exists, check this out

Delete all the beans from a Collection.

public static int delete(Collection<?> c)
                  throws javax.persistence.OptimisticLockException
Victor
  • 907
  • 2
  • 17
  • 42
  • I can't get the link to load; does this actually delete the records from the DB, or just the entities in the model? – Nate T Jul 29 '20 at 19:28
  • accidentally posted above comment as an answer earlier today. It was meant as a comment for @Victor – Nate T Jul 29 '20 at 19:30