cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <>
Subject Re: delete from ... where ... in (...)
Date Fri, 30 May 2008 13:42:50 GMT
Wow, you just gave me a Star Wars flashback.  If we make it to C3PO,
we'll be *golden*!  :-)

If you want to execute that exact SQL, you could do it with
SQLTemplate.  For example, in one of my demo/test projects, I have:

    sqlQuery = new SQLTemplate(Order.class, "DELETE FROM Orders");

If you need it more dynamic, look at inExp() on this page:

You'd then make an Expression and perform query them/fetch them, then
delete them.  There might be an easier way to do this, but I know this
approach would keep your Cayenne object graph in sync (the SQLTemplate
can get things out of sync).  Something like:

    Expression exp = ExpressionFactory.inExp("oid", values);
    SelectQuery select = new SelectQuery(Artist.class, exp);
    List list = dataContext.performQuery(select);
    // loop over list and:
    // then save


PS. The "oid" field needs to be mapped in the above example ...

On Fri, May 30, 2008 at 9:27 AM, Borut BolĨina <> wrote:
> Hi,
> what is the C3M4 prefered way of doing this SQL equivalent: DELETE FROM
> Artist WHERE Oid IN (1,4,8,9);
> Thanks,
> Borut
View raw message