Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] DeleteAllQuery selectionCriteria ignored?

Ok. But it doesn't work...?

My OneToMany mapping on my Defect entity is defined like this.

    @PrivateOwned
    @OneToMany(cascade = CascadeType.PERSIST)
    private Collection<DefectReference> causedBy = new ArrayList<DefectReference>();

This code:

        ReadAllQuery readQuery = new ReadAllQuery(Defect.class);
        ExpressionBuilder defectCriteria = readQuery.getExpressionBuilder();
        _expression_ selectionCriteria = defectCriteria.anyOf("causedBy").get("referenceId").equal(entity.getObjectId());
        readQuery.setSelectionCriteria(selectionCriteria);
        Collection<Defect> defects = (Collection<Defect>) this.entityManager.getActiveSession().executeQuery(readQuery);
        for (Defect defect : defects) {
            this.entityManager.remove(defect);
        }

will produce this sql, that looks ok to me.

2009-01-15 20:54:17,911 [main] DEBUG [EL Fine]: ClientSession(18231691)--Connection(967734)--DELETE FROM DEFECT_REFERENCE WHERE (Defect_ID = ?)
    bind => [301]

2009-01-15 20:54:17,958 [main] DEBUG [EL Fine]: ClientSession(18231691)--Connection(967734)--DELETE FROM REFERENCE WHERE (ID = ?)
    bind => [301]

2009-01-15 20:54:18,005 [main] DEBUG [EL Fine]: ClientSession(18231691)--Connection(967734)--DELETE FROM DEFECT WHERE ((ID = ?) AND (VERSION = ?))
    bind => [301, 1]

If I change this to a DeleteAllQuery like this, that afaik should do the same thing:

        DeleteAllQuery deleteQuery = new DeleteAllQuery(Defect.class);
        ExpressionBuilder defect = deleteQuery.getExpressionBuilder();
        _expression_ selectionCriteria = defect.anyOf("causedBy").get("referenceId").equal(entity.getObjectId());
        deleteQuery.setSelectionCriteria(selectionCriteria);
        deleteQuery.setShouldDeferExecutionInUOW(false);
        this.entityManager.getActiveSession().executeQuery(deleteQuery);

But the sql looks like this :-P

2009-01-15 20:51:47,909 [main] DEBUG [EL Fine]: ClientSession(28847465)--Connection(11363603)--DELETE FROM DEFECT_REFERENCE WHERE EXISTS(SELECT DISTINCT t1.ID FROM REFERENCE t0, DEFECT_REFERENCE t2, DEFECT t1 WHERE ((t0.REFERENCEID = ?) AND (((t2.Defect_ID = t1.ID) AND (t0.ID = t2.causedBy_ID)) AND (t0.DTYPE = ?))) AND t1.ID = DEFECT_REFERENCE.Defect_ID)
    bind => [32c2a56a-e9ec-45ad-8d0d-08fa268ad651, DEFECT]

2009-01-15 20:51:47,972 [main] DEBUG [EL Fine]: ClientSession(28847465)--Connection(11363603)--DELETE FROM DEFECT WHERE EXISTS(SELECT DISTINCT t1.ID FROM REFERENCE t0, DEFECT_REFERENCE t2, DEFECT t1 WHERE ((t0.REFERENCEID = ?) AND (((t2.Defect_ID = t1.ID) AND (t0.ID = t2.causedBy_ID)) AND (t0.DTYPE = ?))) AND t1.ID = DEFECT.ID)
    bind => [32c2a56a-e9ec-45ad-8d0d-08fa268ad651, DEFECT]

Am I missing something?

 /Magnus Heino


On Thu, Jan 15, 2009 at 5:56 PM, Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx> wrote:
Should be:
        ExpressionBuilder builder = query.getExpressionBuilder();
        _expression_ selectionCriteria = builder.anyOf("causedBy").get("referenceId").equal(entity.getObjectId());
----- Original Message -----
From: Magnus Heino
Sent: Thursday, January 15, 2009 10:00 AM
Subject: [eclipselink-users] DeleteAllQuery selectionCriteria ignored?


Hi.

Why does this code:

public void deleteEntityDefects(final ChangeObject entity) {
        DeleteAllQuery query = new DeleteAllQuery(Defect.class);
        ExpressionBuilder selectionCriteria = query.getExpressionBuilder();
        selectionCriteria.anyOf("causedBy").get("referenceId").equal(entity.getObjectId());
        query.setSelectionCriteria(selectionCriteria);
        query.setShouldDeferExecutionInUOW(false);
        this.entityManager.getActiveSession().executeQuery(query);
    }

produce this sql:

DELETE FROM DEFECT_REFERENCE WHERE EXISTS(SELECT ID FROM DEFECT WHERE ID = DEFECT_REFERENCE.Defect_ID)

DELETE FROM DEFECT

It seems as if the selectionCriteria is being ignored?

 /Magnus Heino


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top