@Override public void removeRequest(Requests request) { if (null != request) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); request = (Requests) sess.get(Requests.class, request.getId()); List<Contacts> contTemp = request.getContacts(); List<Products> prodTemp = request.getProducts(); if (contTemp != null && contTemp.size() != 0) { sess.enableFetchProfile("requests-with-products"); contTemp = contactsDAO.getFromProxy(contTemp); for (Contacts contact : contTemp) { contact.getConnectedRequests().remove(request); sess.update(contact); } } if (prodTemp != null && prodTemp.size() != 0) { sess.enableFetchProfile("requests-with-products"); prodTemp = productsDAO.getFromProxy(prodTemp); for (Products product : prodTemp) { product.getRequestsForProduct().remove(request); sess.update(product); } } sess.update(request); sessionFactory.getCurrentSession().delete(request); } }
@Override public void addRequest(Requests request) { sessionFactory.getCurrentSession().save(request); List<Contacts> contTemp = request.getContacts(); List<Products> prodTemp = request.getProducts(); if (contTemp != null && contTemp.size() != 0) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("requests-with-products"); contTemp = contactsDAO.getFromProxy(contTemp); for (Contacts contact : contTemp) { contact.getConnectedRequests().add(request); contactsDAO.changeContact(contact); } } if (prodTemp != null && prodTemp.size() != 0) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("requests-with-products"); prodTemp = productsDAO.getFromProxy(prodTemp); for (Products product : prodTemp) { product.getRequestsForProduct().add(request); productsDAO.changeProduct(product); } } }