質問

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