public void edit(Account account) throws IllegalOrphanException, NonexistentEntityException, Exception {
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);
}
if (materialStorageNew != null && !materialStorageNew.equals(materialStorageOld)) {
materialStorageNew.getAccountCollection().add(account);
materialStorageNew = em.merge(materialStorageNew);
}
for (Storagetab storagetabCollectionNewStoragetab : storagetabCollectionNew) {
if (!storagetabCollectionOld.contains(storagetabCollectionNewStoragetab)) {
Account oldAccountOfStoragetabCollectionNewStoragetab = storagetabCollectionNewStoragetab.getAccount();
storagetabCollectionNewStoragetab.setAccount(account);
storagetabCollectionNewStoragetab = em.merge(storagetabCollectionNewStoragetab);
if (oldAccountOfStoragetabCollectionNewStoragetab != null && !oldAccountOfStoragetabCollectionNewStoragetab.equals(account)) {
oldAccountOfStoragetabCollectionNewStoragetab.getStoragetabCollection().remove(storagetabCollectionNewStoragetab);
oldAccountOfStoragetabCollectionNewStoragetab = em.merge(oldAccountOfStoragetabCollectionNewStoragetab);
}
}
}
for (Factionstat factionstatCollectionNewFactionstat : factionstatCollectionNew) {
if (!factionstatCollectionOld.contains(factionstatCollectionNewFactionstat)) {
Account oldAccountOfFactionstatCollectionNewFactionstat = factionstatCollectionNewFactionstat.getAccount();
factionstatCollectionNewFactionstat.setAccount(account);
factionstatCollectionNewFactionstat = em.merge(factionstatCollectionNewFactionstat);
if (oldAccountOfFactionstatCollectionNewFactionstat != null && !oldAccountOfFactionstatCollectionNewFactionstat.equals(account)) {
oldAccountOfFactionstatCollectionNewFactionstat.getFactionstatCollection().remove(factionstatCollectionNewFactionstat);
oldAccountOfFactionstatCollectionNewFactionstat = em.merge(oldAccountOfFactionstatCollectionNewFactionstat);
}
}
}
for (Character characterCollectionNewCharacter : characterCollectionNew) {
if (!characterCollectionOld.contains(characterCollectionNewCharacter)) {
Account oldAccountIDOfCharacterCollectionNewCharacter = characterCollectionNewCharacter.getAccountID();
characterCollectionNewCharacter.setAccountID(account);
characterCollectionNewCharacter = em.merge(characterCollectionNewCharacter);
if (oldAccountIDOfCharacterCollectionNewCharacter != null && !oldAccountIDOfCharacterCollectionNewCharacter.equals(account)) {
oldAccountIDOfCharacterCollectionNewCharacter.getCharacterCollection().remove(characterCollectionNewCharacter);
oldAccountIDOfCharacterCollectionNewCharacter = em.merge(oldAccountIDOfCharacterCollectionNewCharacter);
}
}
}
em.getTransaction().commit();