Courserates courserates = enrollment.getCourserates();
if (courserates != null) {
courserates = em.getReference(courserates.getClass(), courserates.getId());
enrollment.setCourserates(courserates);
}
User userId = enrollment.getUserId();
if (userId != null) {
userId = em.getReference(userId.getClass(), userId.getId());
enrollment.setUserId(userId);
}
Courses courseId = enrollment.getCourseId();
if (courseId != null) {
courseId = em.getReference(courseId.getClass(), courseId.getCourseId());
enrollment.setCourseId(courseId);
}
List<Comments> attachedCommentsList = new ArrayList<Comments>();
for (Comments commentsListCommentsToAttach : enrollment.getCommentsList()) {
commentsListCommentsToAttach = em.getReference(commentsListCommentsToAttach.getClass(), commentsListCommentsToAttach.getId());
attachedCommentsList.add(commentsListCommentsToAttach);
}
enrollment.setCommentsList(attachedCommentsList);
em.persist(enrollment);
if (courserates != null) {
Enrollment oldEnrollmentOfCourserates = courserates.getEnrollment();
if (oldEnrollmentOfCourserates != null) {
oldEnrollmentOfCourserates.setCourserates(null);
oldEnrollmentOfCourserates = em.merge(oldEnrollmentOfCourserates);
}
courserates.setEnrollment(enrollment);
courserates = em.merge(courserates);
}
if (userId != null) {
userId.getEnrollmentList().add(enrollment);
userId = em.merge(userId);
}
if (courseId != null) {
courseId.getEnrollmentList().add(enrollment);
courseId = em.merge(courseId);