public void edit(Inventory inventory) throws IllegalOrphanException, NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Inventory persistentInventory = em.find(Inventory.class, inventory.getId());
Collection<Account> accountCollectionOld = persistentInventory.getAccountCollection();
Collection<Account> accountCollectionNew = inventory.getAccountCollection();
Collection<Storagetab> storagetabCollectionOld = persistentInventory.getStoragetabCollection();
Collection<Storagetab> storagetabCollectionNew = inventory.getStoragetabCollection();
Collection<Storeditem> storeditemCollectionOld = persistentInventory.getStoreditemCollection();
Collection<Storeditem> storeditemCollectionNew = inventory.getStoreditemCollection();
Collection<Character> characterCollectionOld = persistentInventory.getCharacterCollection();
Collection<Character> characterCollectionNew = inventory.getCharacterCollection();
Collection<Character> characterCollection1Old = persistentInventory.getCharacterCollection1();
Collection<Character> characterCollection1New = inventory.getCharacterCollection1();
Collection<Character> characterCollection2Old = persistentInventory.getCharacterCollection2();
Collection<Character> characterCollection2New = inventory.getCharacterCollection2();
Collection<Character> characterCollection3Old = persistentInventory.getCharacterCollection3();
Collection<Character> characterCollection3New = inventory.getCharacterCollection3();
Collection<Character> characterCollection4Old = persistentInventory.getCharacterCollection4();
Collection<Character> characterCollection4New = inventory.getCharacterCollection4();
Collection<Character> characterCollection5Old = persistentInventory.getCharacterCollection5();
Collection<Character> characterCollection5New = inventory.getCharacterCollection5();
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 inventoryID field is not nullable.");
}
}
for (Storeditem storeditemCollectionOldStoreditem : storeditemCollectionOld) {
if (!storeditemCollectionNew.contains(storeditemCollectionOldStoreditem)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Storeditem " + storeditemCollectionOldStoreditem + " since its inventory field is not nullable.");
}
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
Collection<Account> attachedAccountCollectionNew = new ArrayList<Account>();
for (Account accountCollectionNewAccountToAttach : accountCollectionNew) {
accountCollectionNewAccountToAttach = em.getReference(accountCollectionNewAccountToAttach.getClass(), accountCollectionNewAccountToAttach.getEMail());
attachedAccountCollectionNew.add(accountCollectionNewAccountToAttach);
}
accountCollectionNew = attachedAccountCollectionNew;
inventory.setAccountCollection(accountCollectionNew);
Collection<Storagetab> attachedStoragetabCollectionNew = new ArrayList<Storagetab>();
for (Storagetab storagetabCollectionNewStoragetabToAttach : storagetabCollectionNew) {
storagetabCollectionNewStoragetabToAttach = em.getReference(storagetabCollectionNewStoragetabToAttach.getClass(), storagetabCollectionNewStoragetabToAttach.getStoragetabPK());
attachedStoragetabCollectionNew.add(storagetabCollectionNewStoragetabToAttach);
}
storagetabCollectionNew = attachedStoragetabCollectionNew;
inventory.setStoragetabCollection(storagetabCollectionNew);
Collection<Storeditem> attachedStoreditemCollectionNew = new ArrayList<Storeditem>();
for (Storeditem storeditemCollectionNewStoreditemToAttach : storeditemCollectionNew) {
storeditemCollectionNewStoreditemToAttach = em.getReference(storeditemCollectionNewStoreditemToAttach.getClass(), storeditemCollectionNewStoreditemToAttach.getStoreditemPK());
attachedStoreditemCollectionNew.add(storeditemCollectionNewStoreditemToAttach);
}
storeditemCollectionNew = attachedStoreditemCollectionNew;
inventory.setStoreditemCollection(storeditemCollectionNew);
Collection<Character> attachedCharacterCollectionNew = new ArrayList<Character>();
for (Character characterCollectionNewCharacterToAttach : characterCollectionNew) {
characterCollectionNewCharacterToAttach = em.getReference(characterCollectionNewCharacterToAttach.getClass(), characterCollectionNewCharacterToAttach.getId());
attachedCharacterCollectionNew.add(characterCollectionNewCharacterToAttach);
}
characterCollectionNew = attachedCharacterCollectionNew;
inventory.setCharacterCollection(characterCollectionNew);
Collection<Character> attachedCharacterCollection1New = new ArrayList<Character>();
for (Character characterCollection1NewCharacterToAttach : characterCollection1New) {
characterCollection1NewCharacterToAttach = em.getReference(characterCollection1NewCharacterToAttach.getClass(), characterCollection1NewCharacterToAttach.getId());
attachedCharacterCollection1New.add(characterCollection1NewCharacterToAttach);
}
characterCollection1New = attachedCharacterCollection1New;
inventory.setCharacterCollection1(characterCollection1New);
Collection<Character> attachedCharacterCollection2New = new ArrayList<Character>();
for (Character characterCollection2NewCharacterToAttach : characterCollection2New) {
characterCollection2NewCharacterToAttach = em.getReference(characterCollection2NewCharacterToAttach.getClass(), characterCollection2NewCharacterToAttach.getId());
attachedCharacterCollection2New.add(characterCollection2NewCharacterToAttach);
}
characterCollection2New = attachedCharacterCollection2New;
inventory.setCharacterCollection2(characterCollection2New);
Collection<Character> attachedCharacterCollection3New = new ArrayList<Character>();
for (Character characterCollection3NewCharacterToAttach : characterCollection3New) {
characterCollection3NewCharacterToAttach = em.getReference(characterCollection3NewCharacterToAttach.getClass(), characterCollection3NewCharacterToAttach.getId());
attachedCharacterCollection3New.add(characterCollection3NewCharacterToAttach);
}
characterCollection3New = attachedCharacterCollection3New;
inventory.setCharacterCollection3(characterCollection3New);
Collection<Character> attachedCharacterCollection4New = new ArrayList<Character>();
for (Character characterCollection4NewCharacterToAttach : characterCollection4New) {
characterCollection4NewCharacterToAttach = em.getReference(characterCollection4NewCharacterToAttach.getClass(), characterCollection4NewCharacterToAttach.getId());
attachedCharacterCollection4New.add(characterCollection4NewCharacterToAttach);
}
characterCollection4New = attachedCharacterCollection4New;
inventory.setCharacterCollection4(characterCollection4New);
Collection<Character> attachedCharacterCollection5New = new ArrayList<Character>();
for (Character characterCollection5NewCharacterToAttach : characterCollection5New) {
characterCollection5NewCharacterToAttach = em.getReference(characterCollection5NewCharacterToAttach.getClass(), characterCollection5NewCharacterToAttach.getId());
attachedCharacterCollection5New.add(characterCollection5NewCharacterToAttach);
}
characterCollection5New = attachedCharacterCollection5New;
inventory.setCharacterCollection5(characterCollection5New);
inventory = em.merge(inventory);
for (Account accountCollectionOldAccount : accountCollectionOld) {
if (!accountCollectionNew.contains(accountCollectionOldAccount)) {
accountCollectionOldAccount.setMaterialStorage(null);
accountCollectionOldAccount = em.merge(accountCollectionOldAccount);
}
}
for (Account accountCollectionNewAccount : accountCollectionNew) {
if (!accountCollectionOld.contains(accountCollectionNewAccount)) {
Inventory oldMaterialStorageOfAccountCollectionNewAccount = accountCollectionNewAccount.getMaterialStorage();
accountCollectionNewAccount.setMaterialStorage(inventory);
accountCollectionNewAccount = em.merge(accountCollectionNewAccount);
if (oldMaterialStorageOfAccountCollectionNewAccount != null && !oldMaterialStorageOfAccountCollectionNewAccount.equals(inventory)) {
oldMaterialStorageOfAccountCollectionNewAccount.getAccountCollection().remove(accountCollectionNewAccount);
oldMaterialStorageOfAccountCollectionNewAccount = em.merge(oldMaterialStorageOfAccountCollectionNewAccount);
}
}
}
for (Storagetab storagetabCollectionNewStoragetab : storagetabCollectionNew) {
if (!storagetabCollectionOld.contains(storagetabCollectionNewStoragetab)) {
Inventory oldInventoryIDOfStoragetabCollectionNewStoragetab = storagetabCollectionNewStoragetab.getInventoryID();
storagetabCollectionNewStoragetab.setInventoryID(inventory);
storagetabCollectionNewStoragetab = em.merge(storagetabCollectionNewStoragetab);
if (oldInventoryIDOfStoragetabCollectionNewStoragetab != null && !oldInventoryIDOfStoragetabCollectionNewStoragetab.equals(inventory)) {
oldInventoryIDOfStoragetabCollectionNewStoragetab.getStoragetabCollection().remove(storagetabCollectionNewStoragetab);
oldInventoryIDOfStoragetabCollectionNewStoragetab = em.merge(oldInventoryIDOfStoragetabCollectionNewStoragetab);
}
}
}
for (Storeditem storeditemCollectionNewStoreditem : storeditemCollectionNew) {
if (!storeditemCollectionOld.contains(storeditemCollectionNewStoreditem)) {
Inventory oldInventoryOfStoreditemCollectionNewStoreditem = storeditemCollectionNewStoreditem.getInventory();
storeditemCollectionNewStoreditem.setInventory(inventory);
storeditemCollectionNewStoreditem = em.merge(storeditemCollectionNewStoreditem);
if (oldInventoryOfStoreditemCollectionNewStoreditem != null && !oldInventoryOfStoreditemCollectionNewStoreditem.equals(inventory)) {
oldInventoryOfStoreditemCollectionNewStoreditem.getStoreditemCollection().remove(storeditemCollectionNewStoreditem);
oldInventoryOfStoreditemCollectionNewStoreditem = em.merge(oldInventoryOfStoreditemCollectionNewStoreditem);
}
}
}
for (Character characterCollectionOldCharacter : characterCollectionOld) {
if (!characterCollectionNew.contains(characterCollectionOldCharacter)) {
characterCollectionOldCharacter.setEquipmentPack(null);
characterCollectionOldCharacter = em.merge(characterCollectionOldCharacter);
}
}
for (Character characterCollectionNewCharacter : characterCollectionNew) {
if (!characterCollectionOld.contains(characterCollectionNewCharacter)) {
Inventory oldEquipmentPackOfCharacterCollectionNewCharacter = characterCollectionNewCharacter.getEquipmentPack();
characterCollectionNewCharacter.setEquipmentPack(inventory);
characterCollectionNewCharacter = em.merge(characterCollectionNewCharacter);
if (oldEquipmentPackOfCharacterCollectionNewCharacter != null && !oldEquipmentPackOfCharacterCollectionNewCharacter.equals(inventory)) {
oldEquipmentPackOfCharacterCollectionNewCharacter.getCharacterCollection().remove(characterCollectionNewCharacter);
oldEquipmentPackOfCharacterCollectionNewCharacter = em.merge(oldEquipmentPackOfCharacterCollectionNewCharacter);
}
}
}
for (Character characterCollection1OldCharacter : characterCollection1Old) {
if (!characterCollection1New.contains(characterCollection1OldCharacter)) {
characterCollection1OldCharacter.setEquipment(null);
characterCollection1OldCharacter = em.merge(characterCollection1OldCharacter);
}
}
for (Character characterCollection1NewCharacter : characterCollection1New) {
if (!characterCollection1Old.contains(characterCollection1NewCharacter)) {
Inventory oldEquipmentOfCharacterCollection1NewCharacter = characterCollection1NewCharacter.getEquipment();
characterCollection1NewCharacter.setEquipment(inventory);
characterCollection1NewCharacter = em.merge(characterCollection1NewCharacter);
if (oldEquipmentOfCharacterCollection1NewCharacter != null && !oldEquipmentOfCharacterCollection1NewCharacter.equals(inventory)) {
oldEquipmentOfCharacterCollection1NewCharacter.getCharacterCollection1().remove(characterCollection1NewCharacter);
oldEquipmentOfCharacterCollection1NewCharacter = em.merge(oldEquipmentOfCharacterCollection1NewCharacter);
}
}
}
for (Character characterCollection2OldCharacter : characterCollection2Old) {
if (!characterCollection2New.contains(characterCollection2OldCharacter)) {
characterCollection2OldCharacter.setBeltpouch(null);
characterCollection2OldCharacter = em.merge(characterCollection2OldCharacter);
}
}
for (Character characterCollection2NewCharacter : characterCollection2New) {
if (!characterCollection2Old.contains(characterCollection2NewCharacter)) {
Inventory oldBeltpouchOfCharacterCollection2NewCharacter = characterCollection2NewCharacter.getBeltpouch();
characterCollection2NewCharacter.setBeltpouch(inventory);
characterCollection2NewCharacter = em.merge(characterCollection2NewCharacter);
if (oldBeltpouchOfCharacterCollection2NewCharacter != null && !oldBeltpouchOfCharacterCollection2NewCharacter.equals(inventory)) {
oldBeltpouchOfCharacterCollection2NewCharacter.getCharacterCollection2().remove(characterCollection2NewCharacter);
oldBeltpouchOfCharacterCollection2NewCharacter = em.merge(oldBeltpouchOfCharacterCollection2NewCharacter);
}
}
}
for (Character characterCollection3OldCharacter : characterCollection3Old) {
if (!characterCollection3New.contains(characterCollection3OldCharacter)) {
characterCollection3OldCharacter.setBag2(null);
characterCollection3OldCharacter = em.merge(characterCollection3OldCharacter);
}
}
for (Character characterCollection3NewCharacter : characterCollection3New) {
if (!characterCollection3Old.contains(characterCollection3NewCharacter)) {
Inventory oldBag2OfCharacterCollection3NewCharacter = characterCollection3NewCharacter.getBag2();
characterCollection3NewCharacter.setBag2(inventory);
characterCollection3NewCharacter = em.merge(characterCollection3NewCharacter);
if (oldBag2OfCharacterCollection3NewCharacter != null && !oldBag2OfCharacterCollection3NewCharacter.equals(inventory)) {
oldBag2OfCharacterCollection3NewCharacter.getCharacterCollection3().remove(characterCollection3NewCharacter);
oldBag2OfCharacterCollection3NewCharacter = em.merge(oldBag2OfCharacterCollection3NewCharacter);
}
}
}
for (Character characterCollection4OldCharacter : characterCollection4Old) {
if (!characterCollection4New.contains(characterCollection4OldCharacter)) {
characterCollection4OldCharacter.setBag1(null);
characterCollection4OldCharacter = em.merge(characterCollection4OldCharacter);
}
}
for (Character characterCollection4NewCharacter : characterCollection4New) {
if (!characterCollection4Old.contains(characterCollection4NewCharacter)) {
Inventory oldBag1OfCharacterCollection4NewCharacter = characterCollection4NewCharacter.getBag1();
characterCollection4NewCharacter.setBag1(inventory);
characterCollection4NewCharacter = em.merge(characterCollection4NewCharacter);
if (oldBag1OfCharacterCollection4NewCharacter != null && !oldBag1OfCharacterCollection4NewCharacter.equals(inventory)) {
oldBag1OfCharacterCollection4NewCharacter.getCharacterCollection4().remove(characterCollection4NewCharacter);
oldBag1OfCharacterCollection4NewCharacter = em.merge(oldBag1OfCharacterCollection4NewCharacter);
}
}
}
for (Character characterCollection5OldCharacter : characterCollection5Old) {
if (!characterCollection5New.contains(characterCollection5OldCharacter)) {
characterCollection5OldCharacter.setBackpack(null);
characterCollection5OldCharacter = em.merge(characterCollection5OldCharacter);
}
}
for (Character characterCollection5NewCharacter : characterCollection5New) {
if (!characterCollection5Old.contains(characterCollection5NewCharacter)) {
Inventory oldBackpackOfCharacterCollection5NewCharacter = characterCollection5NewCharacter.getBackpack();
characterCollection5NewCharacter.setBackpack(inventory);
characterCollection5NewCharacter = em.merge(characterCollection5NewCharacter);
if (oldBackpackOfCharacterCollection5NewCharacter != null && !oldBackpackOfCharacterCollection5NewCharacter.equals(inventory)) {
oldBackpackOfCharacterCollection5NewCharacter.getCharacterCollection5().remove(characterCollection5NewCharacter);
oldBackpackOfCharacterCollection5NewCharacter = em.merge(oldBackpackOfCharacterCollection5NewCharacter);
}
}
}
em.getTransaction().commit();