public void edit(Tag tag) throws IllegalOrphanException, NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Tag persistentTag = em.find(Tag.class, tag.getId());
List<Coursetag> coursetagListOld = persistentTag.getCoursetagList();
List<Coursetag> coursetagListNew = tag.getCoursetagList();
List<Tagcorrelations> tagcorrelationsListOld = persistentTag.getTagcorrelationsList();
List<Tagcorrelations> tagcorrelationsListNew = tag.getTagcorrelationsList();
List<Tagcorrelations> tagcorrelationsList1Old = persistentTag.getTagcorrelationsList1();
List<Tagcorrelations> tagcorrelationsList1New = tag.getTagcorrelationsList1();
List<String> illegalOrphanMessages = null;
for (Coursetag coursetagListOldCoursetag : coursetagListOld) {
if (!coursetagListNew.contains(coursetagListOldCoursetag)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Coursetag " + coursetagListOldCoursetag + " since its tagId field is not nullable.");
}
}
for (Tagcorrelations tagcorrelationsListOldTagcorrelations : tagcorrelationsListOld) {
if (!tagcorrelationsListNew.contains(tagcorrelationsListOldTagcorrelations)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Tagcorrelations " + tagcorrelationsListOldTagcorrelations + " since its referencedTagId field is not nullable.");
}
}
for (Tagcorrelations tagcorrelationsList1OldTagcorrelations : tagcorrelationsList1Old) {
if (!tagcorrelationsList1New.contains(tagcorrelationsList1OldTagcorrelations)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Tagcorrelations " + tagcorrelationsList1OldTagcorrelations + " since its mainTagId field is not nullable.");
}
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
List<Coursetag> attachedCoursetagListNew = new ArrayList<Coursetag>();
for (Coursetag coursetagListNewCoursetagToAttach : coursetagListNew) {
coursetagListNewCoursetagToAttach = em.getReference(coursetagListNewCoursetagToAttach.getClass(), coursetagListNewCoursetagToAttach.getId());
attachedCoursetagListNew.add(coursetagListNewCoursetagToAttach);
}
coursetagListNew = attachedCoursetagListNew;
tag.setCoursetagList(coursetagListNew);
List<Tagcorrelations> attachedTagcorrelationsListNew = new ArrayList<Tagcorrelations>();
for (Tagcorrelations tagcorrelationsListNewTagcorrelationsToAttach : tagcorrelationsListNew) {
tagcorrelationsListNewTagcorrelationsToAttach = em.getReference(tagcorrelationsListNewTagcorrelationsToAttach.getClass(), tagcorrelationsListNewTagcorrelationsToAttach.getId());
attachedTagcorrelationsListNew.add(tagcorrelationsListNewTagcorrelationsToAttach);
}
tagcorrelationsListNew = attachedTagcorrelationsListNew;
tag.setTagcorrelationsList(tagcorrelationsListNew);
List<Tagcorrelations> attachedTagcorrelationsList1New = new ArrayList<Tagcorrelations>();
for (Tagcorrelations tagcorrelationsList1NewTagcorrelationsToAttach : tagcorrelationsList1New) {
tagcorrelationsList1NewTagcorrelationsToAttach = em.getReference(tagcorrelationsList1NewTagcorrelationsToAttach.getClass(), tagcorrelationsList1NewTagcorrelationsToAttach.getId());
attachedTagcorrelationsList1New.add(tagcorrelationsList1NewTagcorrelationsToAttach);
}
tagcorrelationsList1New = attachedTagcorrelationsList1New;
tag.setTagcorrelationsList1(tagcorrelationsList1New);
tag = em.merge(tag);
for (Coursetag coursetagListNewCoursetag : coursetagListNew) {
if (!coursetagListOld.contains(coursetagListNewCoursetag)) {
Tag oldTagIdOfCoursetagListNewCoursetag = coursetagListNewCoursetag.getTagId();
coursetagListNewCoursetag.setTagId(tag);
coursetagListNewCoursetag = em.merge(coursetagListNewCoursetag);
if (oldTagIdOfCoursetagListNewCoursetag != null && !oldTagIdOfCoursetagListNewCoursetag.equals(tag)) {
oldTagIdOfCoursetagListNewCoursetag.getCoursetagList().remove(coursetagListNewCoursetag);
oldTagIdOfCoursetagListNewCoursetag = em.merge(oldTagIdOfCoursetagListNewCoursetag);
}
}
}
for (Tagcorrelations tagcorrelationsListNewTagcorrelations : tagcorrelationsListNew) {
if (!tagcorrelationsListOld.contains(tagcorrelationsListNewTagcorrelations)) {
Tag oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations = tagcorrelationsListNewTagcorrelations.getReferencedTagId();
tagcorrelationsListNewTagcorrelations.setReferencedTagId(tag);
tagcorrelationsListNewTagcorrelations = em.merge(tagcorrelationsListNewTagcorrelations);
if (oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations != null && !oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations.equals(tag)) {
oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations.getTagcorrelationsList().remove(tagcorrelationsListNewTagcorrelations);
oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations = em.merge(oldReferencedTagIdOfTagcorrelationsListNewTagcorrelations);
}
}
}
for (Tagcorrelations tagcorrelationsList1NewTagcorrelations : tagcorrelationsList1New) {
if (!tagcorrelationsList1Old.contains(tagcorrelationsList1NewTagcorrelations)) {
Tag oldMainTagIdOfTagcorrelationsList1NewTagcorrelations = tagcorrelationsList1NewTagcorrelations.getMainTagId();
tagcorrelationsList1NewTagcorrelations.setMainTagId(tag);
tagcorrelationsList1NewTagcorrelations = em.merge(tagcorrelationsList1NewTagcorrelations);
if (oldMainTagIdOfTagcorrelationsList1NewTagcorrelations != null && !oldMainTagIdOfTagcorrelationsList1NewTagcorrelations.equals(tag)) {
oldMainTagIdOfTagcorrelationsList1NewTagcorrelations.getTagcorrelationsList1().remove(tagcorrelationsList1NewTagcorrelations);
oldMainTagIdOfTagcorrelationsList1NewTagcorrelations = em.merge(oldMainTagIdOfTagcorrelationsList1NewTagcorrelations);
}
}
}
em.getTransaction().commit();