SHARE
TWEET

Untitled

a guest Feb 27th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void removeObjectsExercise() {
  2.         List<Town> towns = this.entityManager
  3.                 .createQuery("SELECT t FROM Town AS t " +
  4.                         "WHERE length(t.name) > 5", Town.class)
  5.                 .getResultList();
  6.  
  7.  
  8.         this.entityManager.getTransaction().begin();
  9.  
  10.         towns
  11.                 .forEach(this.entityManager::detach);
  12.         this.entityManager.flush();
  13.         this.entityManager.getTransaction().commit();
  14.  
  15.         entityManager.getTransaction().begin();
  16.         entityManager.createQuery("UPDATE Town t SET t.name = lower(t.name) " +
  17.                 "WHERE length(t.name) <= 5 ").executeUpdate();
  18.         entityManager.getTransaction().commit();
  19.         entityManager.close();
  20.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top