문제

I need to delete few rown according with given data:

DELETE FORM mytable WHERE cond1 = 1 AND cond2 = 2;

But I found no methods which allow to delete object with given way. There is method that allows to delete a single object(Model.delete()), but it is not effective way for list of object. I do not want to execute a raw SQL request because it's depends of SQL dialect and it's risky for SQL-injections.

So what it a right way to implement this query?

도움이 되었습니까?

해결책

You may want to give Ebean.createUpdate() a try. As the javadoc describes, this method accepts an ORM update string.

The orm update differs from the sql update in that it you can use the bean name and bean property names rather than table and column names.

For example:

Update<Customer> upd = Ebean.createUpdate(Customer.class, "DELETE Customer WHERE email=:email");
upd.set("email", "someone@somewhe.re");
return upd.execute();

다른 팁

Use com.avaje.ebean.SqlUpdate for this. i.e.

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

Also it's possible to update many - see also other answer

I do it this way:

Ebean.deleteAll(UserType.find.all());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top