문제

I need to delete some rows from table according with some criterias. SQL query should be like this:

DELETE FROM tablename WHERE cond1 = 1 AND cond2 = 2

But I found no such methods. I can delete a single model:

model.delete();

Or I can get a list of models accorsing with given critetias:

Model.FINDER.where().eq("cond1", 1).eq("cond2", 2).findList();

Off course, I can get list of models and delete them in the cycle, but this is very bad solution. Instead of one SQL-request I getting potentially unlimited SQL-requests. I also do not want to execute raw SQL code because it's can break SQL cross-platform compatibility.

It really is frequently task. Is that true that Play Framework has no means of work with it?

도움이 되었습니까?

해결책

Indeed deleting objects one-by-one is bad solution, fortunately Ebean allows you to perform SqlUpdate like:

SqlUpdate tangoDown = Ebean.createSqlUpdate("DELETE FROM table_name WHERE id = 123");
tangoDown.execute(); 

see: other question for parametrized queries.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top