public Boolean verifAndAssignRestaurant(String code, Integer IdOwner) { Owner owner = factoryServiceLocal.getOwnerEjb().findById(IdOwner, Owner.class); String jpql = "select e from ValidateOwnerRestaurant e where e.code =:code and e.owner.id=:owner"; Query sql = entityManager.createQuery(jpql); sql.setParameter("code", code); sql.setParameter("owner", IdOwner); ValidateOwnerRestaurant ownerRestaurant = (ValidateOwnerRestaurant) sql.getSingleResult(); if (ownerRestaurant == null) return false; else { System.out.println(ownerRestaurant); Restaurant restaurant = factoryServiceLocal .getRestaurantEjb() .findById(ownerRestaurant.getRestaurant().getId(), Restaurant.class); factoryServiceLocal.getValidateOwnerRestaurantEjb().delete(ownerRestaurant); factoryServiceLocal.getRestaurantEjb().delete(restaurant); restaurant = new Complaint( restaurant.getId(), restaurant.getName(), restaurant.getAddress(), restaurant.getEmail(), restaurant.getCategory(), null, null); restaurant.setOwner(owner); factoryServiceLocal.getRestaurantEjb().add(restaurant); ownerRestaurant.getRestaurant().setOwner(owner); return true; } }