Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package test.service;
  2.  
  3. import java.util.List;
  4.  
  5. import it.zero11.vaadin.course.utils.JPAUtils;
  6. import test.model.Product;
  7.  
  8. public class ProductService {
  9.  
  10. public void addProduct(Product p) {
  11. JPAUtils.runInTransaction(entityManager -> {
  12. entityManager.persist(p);
  13. });
  14. }
  15.  
  16. public List<Product> searchAll() {
  17. return JPAUtils.runInTransaction((entityManager) -> {
  18. return entityManager.createQuery("from Product").getResultList();
  19. });
  20. }
  21.  
  22. public void remove(Product p) {
  23. JPAUtils.runInTransaction((entityManager) -> {
  24. entityManager.remove(entityManager.find(p.getClass(), p.getId()));
  25. });
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement