public void edit(Comments comments) throws IllegalOrphanException, NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Comments persistentComments = em.find(Comments.class, comments.getId());
Commentrates commentratesOld = persistentComments.getCommentrates();
Commentrates commentratesNew = comments.getCommentrates();
Enrollment enrollmentIdOld = persistentComments.getEnrollmentId();
Enrollment enrollmentIdNew = comments.getEnrollmentId();
List<String> illegalOrphanMessages = null;
if (commentratesOld != null && !commentratesOld.equals(commentratesNew)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Commentrates " + commentratesOld + " since its comments field is not nullable.");
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
if (commentratesNew != null) {
commentratesNew = em.getReference(commentratesNew.getClass(), commentratesNew.getId());
comments.setCommentrates(commentratesNew);
}
if (enrollmentIdNew != null) {
enrollmentIdNew = em.getReference(enrollmentIdNew.getClass(), enrollmentIdNew.getId());
comments.setEnrollmentId(enrollmentIdNew);
}
comments = em.merge(comments);
if (commentratesNew != null && !commentratesNew.equals(commentratesOld)) {
Comments oldCommentsOfCommentrates = commentratesNew.getComments();
if (oldCommentsOfCommentrates != null) {
oldCommentsOfCommentrates.setCommentrates(null);
oldCommentsOfCommentrates = em.merge(oldCommentsOfCommentrates);
}
commentratesNew.setComments(comments);
commentratesNew = em.merge(commentratesNew);
}