Some code samples might help you out. Try this:
and this I found in communitycommons, folder Batches, deleteAll:
return XPath.create(this.getContext(), entityType).deleteAll();
or this example in Unittest – findAllTests:
/* * Remove all modules without tests */ XPath.create(context, TestSuite.class).not().hasReference(UnitTest.MemberNames.UnitTest_TestSuite, UnitTest.entityName).close().deleteAll();
If you already have the community commons in your app it is already there. Look at the deleteAll action in the community commons: https://marketplace.mendix.com/link/component/170
This job is perfectly doable in Mendix itself. Why do you want to use Java for this?