Retrieving objects IDs without instantiating them in Java

I need to delete a large number of objects within a Java action which uses an IRemoveBatch. The objects being deleted are all those with a status field which has a particular value, so I am using Core.retrieveXPathQueryEscaped like this: batchList = Core.retrieveXPathQueryEscaped (this.getContext(), "//%s[%s='%s']", BATCH_SIZE, 0, new LinkedHashMap<String,String>(), 0, myObject.entityName, myObject.MemberNames.myObjectStatus.toString(), targetStatus.toString()); for(IMendixObject obj : batchList) { myRemoveBatch.removeObject (obj); } myRemoveBatch.commit(); My problem is that this instantiates each object, i.e. builds an IMendixObject, for every object going on the batch, which takes a long time. Is building all the objects avoidable? I think I ought to be able to use just the IMendixIdentifier, since I never need to access any of the object's attributes at any time.
2 answers

No, unfortunately, if you want to delete a MendixObject, you always need to instantiate it. If you'd like to be able to delete by ids or delete by xpath you can request those features at MXDN.


It is possible to use some more complex java code to remove the objects. In my experience this could be faster then retrieving a complete IMendixObject.

This is what the code does: First it retrieves all objects id's with oql, the only thing the xas does is creating an identifier for each object.
Then for each id in the result a new thread is started by the core to remove the id's, because I don't want to have to many open request the code waits after 50 calls untill the core is finished.

You can try if this works for you. But keep in mind that this could be a pretty heavy process for your server and if you have to many async remove calls the server could slow down so much that users will experience some performance problems.

private void removeObjects( ) throws CoreException {
    IDataTable table = Core.retrieveOQLDataTable(this.getContext(), "SELECT id FROM moduleName.ObjectType WHERE myObjectStatus = 'targetStatus' ");
    if( table.getRowCount() > 0 ) {
        List<Future<Boolean>> futureList = new ArrayList<Future<Boolean>>();
        List<? extends IDataRow> rows = table.getRows();

        for( IDataRow row : rows ) { 
            IMendixIdentifier id = row.getValue(0);
            futureList.add( Core.removeAsync(this.getContext(), id, true) );

            if( futureList.size() >= 50 )

private void proccessFutureList( List<Future<Boolean>> futureList ) throws CoreException {
    for( Future<Boolean> f : futureList ) {
        try {
        catch (Exception e) {
            throw new CoreException(e);