public void testDeleteExpression() { if (isOnServer()) { // Not work on server. return; } if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test testDeleteExpression skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } JpaEntityManager em = (org.eclipse.persistence.jpa.JpaEntityManager) createEntityManager(); try { beginTransaction(em); String orderString = "DELETE FROM OrderBean o WHERE o.customer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); orderString = "DELETE FROM OrderBean o WHERE o.billedCustomer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); String ejbqlString = "DELETE FROM Customer c WHERE c.name='Karen McDonald' "; int result = em.createQuery(ejbqlString).executeUpdate(); Assert.assertEquals("Delete Expression test failed: customer to delete not found", 1, result); em.flush(); ReadAllQuery raq = new ReadAllQuery(Customer.class, new ExpressionBuilder()); Expression whereClause = raq.getExpressionBuilder().get("name").equal("Karen McDonald"); raq.setSelectionCriteria(whereClause); List customerFound = (List) em.getActiveSession().executeQuery(raq); Assert.assertEquals("Delete Expression test failed", 0, customerFound.size()); } finally { rollbackTransaction(em); } }
public Object[] find(ReadAllQuery dbQuery) { Query query = jpa.createQuery(dbQuery); List l = query.getResultList(); if ((l != null) && (l.size() > 0)) { return l.toArray(); } else { return null; } }