Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test.service;
- import java.util.List;
- import it.zero11.vaadin.course.utils.JPAUtils;
- import test.model.Product;
- public class ProductService {
- public void addProduct(Product p) {
- JPAUtils.runInTransaction(entityManager -> {
- entityManager.persist(p);
- });
- }
- public List<Product> searchAll() {
- return JPAUtils.runInTransaction((entityManager) -> {
- return entityManager.createQuery("from Product").getResultList();
- });
- }
- public void remove(Product p) {
- JPAUtils.runInTransaction((entityManager) -> {
- entityManager.remove(entityManager.find(p.getClass(), p.getId()));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement