EntityManager entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); // persist some entities entityManager.clear(); // all entities are removed from the persistence context entityManager.getTransaction().commit(); entityManager.close();
EntityManager entityManager = entityManagerFactory.createEntityManager(); Query query = entityManager.createNamedQuery("deleteAllEntities"); // execute the named query to remove all entities query.executeUpdate(); entityManager.close();Package library: javax.persistence.