Advertisement
N_Damyanov

2. Remove Objects

Jun 23rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. private void removeTowns() {
  2.         this.entityManager.getTransaction().begin();
  3.  
  4.         List<Town> towns = this.entityManager.createQuery("FROM Town", Town.class).getResultList();
  5.  
  6.         towns.forEach(e -> {
  7.             if (e.getName().length() > 5) {
  8.                 this.entityManager.remove(e);
  9.             } else {
  10.                 e.setName(e.getName().toLowerCase());
  11.             }
  12.         });
  13.  
  14.         this.entityManager.flush();
  15.         this.entityManager.getTransaction().commit();
  16.  
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement