Advertisement
nikeza

Untitled

Feb 22nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1.  private void increaseSalary() {
  2.  
  3.         List<Employee> employees = em.createQuery("SELECT e from Employee e  WHERE e.department.id IN (1, 2, 4, 11)", Employee.class)
  4.                 .getResultList();
  5.  
  6.  
  7.         em.getTransaction().begin();
  8.  
  9.         employees.forEach(e->em.detach(e));
  10.         employees.forEach(e->e.setSalary(e.getSalary().multiply(BigDecimal.valueOf(1.12))));
  11.         employees.forEach(e->em.merge(e));
  12.         em.flush();
  13.  
  14.         em.getTransaction().commit();
  15.  
  16.         employees.forEach(e-> System.out.printf("%s %s ($%.2f)%n"
  17.         ,e.getFirstName()
  18.         ,e.getLastName()
  19.         , (e.getSalary())));
  20.  
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement