EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Account persistentAccount = em.find(Account.class, account.getEMail());
Usergroup userGroupOld = persistentAccount.getUserGroup();
Usergroup userGroupNew = account.getUserGroup();
Inventory materialStorageOld = persistentAccount.getMaterialStorage();
Inventory materialStorageNew = account.getMaterialStorage();
Collection<Storagetab> storagetabCollectionOld = persistentAccount.getStoragetabCollection();
Collection<Storagetab> storagetabCollectionNew = account.getStoragetabCollection();
Collection<Factionstat> factionstatCollectionOld = persistentAccount.getFactionstatCollection();
Collection<Factionstat> factionstatCollectionNew = account.getFactionstatCollection();
Collection<Character> characterCollectionOld = persistentAccount.getCharacterCollection();
Collection<Character> characterCollectionNew = account.getCharacterCollection();
List<String> illegalOrphanMessages = null;
for (Storagetab storagetabCollectionOldStoragetab : storagetabCollectionOld) {
if (!storagetabCollectionNew.contains(storagetabCollectionOldStoragetab)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Storagetab " + storagetabCollectionOldStoragetab + " since its account field is not nullable.");
}
}
for (Factionstat factionstatCollectionOldFactionstat : factionstatCollectionOld) {
if (!factionstatCollectionNew.contains(factionstatCollectionOldFactionstat)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Factionstat " + factionstatCollectionOldFactionstat + " since its account field is not nullable.");
}
}
for (Character characterCollectionOldCharacter : characterCollectionOld) {
if (!characterCollectionNew.contains(characterCollectionOldCharacter)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Character " + characterCollectionOldCharacter + " since its accountID field is not nullable.");
}
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
if (userGroupNew != null) {
userGroupNew = em.getReference(userGroupNew.getClass(), userGroupNew.getId());
account.setUserGroup(userGroupNew);
}
if (materialStorageNew != null) {
materialStorageNew = em.getReference(materialStorageNew.getClass(), materialStorageNew.getId());
account.setMaterialStorage(materialStorageNew);
}
Collection<Storagetab> attachedStoragetabCollectionNew = new ArrayList<Storagetab>();
for (Storagetab storagetabCollectionNewStoragetabToAttach : storagetabCollectionNew) {
storagetabCollectionNewStoragetabToAttach = em.getReference(storagetabCollectionNewStoragetabToAttach.getClass(), storagetabCollectionNewStoragetabToAttach.getStoragetabPK());
attachedStoragetabCollectionNew.add(storagetabCollectionNewStoragetabToAttach);
}
storagetabCollectionNew = attachedStoragetabCollectionNew;
account.setStoragetabCollection(storagetabCollectionNew);
Collection<Factionstat> attachedFactionstatCollectionNew = new ArrayList<Factionstat>();
for (Factionstat factionstatCollectionNewFactionstatToAttach : factionstatCollectionNew) {
factionstatCollectionNewFactionstatToAttach = em.getReference(factionstatCollectionNewFactionstatToAttach.getClass(), factionstatCollectionNewFactionstatToAttach.getFactionstatPK());
attachedFactionstatCollectionNew.add(factionstatCollectionNewFactionstatToAttach);
}
factionstatCollectionNew = attachedFactionstatCollectionNew;
account.setFactionstatCollection(factionstatCollectionNew);
Collection<Character> attachedCharacterCollectionNew = new ArrayList<Character>();
for (Character characterCollectionNewCharacterToAttach : characterCollectionNew) {
characterCollectionNewCharacterToAttach = em.getReference(characterCollectionNewCharacterToAttach.getClass(), characterCollectionNewCharacterToAttach.getId());
attachedCharacterCollectionNew.add(characterCollectionNewCharacterToAttach);
}
characterCollectionNew = attachedCharacterCollectionNew;
account.setCharacterCollection(characterCollectionNew);
account = em.merge(account);
if (userGroupOld != null && !userGroupOld.equals(userGroupNew)) {
userGroupOld.getAccountCollection().remove(account);
userGroupOld = em.merge(userGroupOld);
}
if (userGroupNew != null && !userGroupNew.equals(userGroupOld)) {
userGroupNew.getAccountCollection().add(account);
userGroupNew = em.merge(userGroupNew);
}
if (materialStorageOld != null && !materialStorageOld.equals(materialStorageNew)) {
materialStorageOld.getAccountCollection().remove(account);
materialStorageOld = em.merge(materialStorageOld);