EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Item persistentItem = em.find(Item.class, item.getId());
Character customizedForOld = persistentItem.getCustomizedFor();
Character customizedForNew = item.getCustomizedFor();
Itembase baseIDOld = persistentItem.getBaseID();
Itembase baseIDNew = item.getBaseID();
Collection<Itemstat> itemstatCollectionOld = persistentItem.getItemstatCollection();
Collection<Itemstat> itemstatCollectionNew = item.getItemstatCollection();
Collection<Storeditem> storeditemCollectionOld = persistentItem.getStoreditemCollection();
Collection<Storeditem> storeditemCollectionNew = item.getStoreditemCollection();
Collection<Weapon> weaponCollectionOld = persistentItem.getWeaponCollection();
Collection<Weapon> weaponCollectionNew = item.getWeaponCollection();
Collection<Weapon> weaponCollection1Old = persistentItem.getWeaponCollection1();
Collection<Weapon> weaponCollection1New = item.getWeaponCollection1();
List<String> illegalOrphanMessages = null;
for (Itemstat itemstatCollectionOldItemstat : itemstatCollectionOld) {
if (!itemstatCollectionNew.contains(itemstatCollectionOldItemstat)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Itemstat " + itemstatCollectionOldItemstat + " since its item 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 itemID field is not nullable.");
}
}
for (Weapon weaponCollectionOldWeapon : weaponCollectionOld) {
if (!weaponCollectionNew.contains(weaponCollectionOldWeapon)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Weapon " + weaponCollectionOldWeapon + " since its offhand field is not nullable.");
}
}
for (Weapon weaponCollection1OldWeapon : weaponCollection1Old) {
if (!weaponCollection1New.contains(weaponCollection1OldWeapon)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain Weapon " + weaponCollection1OldWeapon + " since its leadhand field is not nullable.");
}
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
if (customizedForNew != null) {
customizedForNew = em.getReference(customizedForNew.getClass(), customizedForNew.getId());
item.setCustomizedFor(customizedForNew);
}
if (baseIDNew != null) {
baseIDNew = em.getReference(baseIDNew.getClass(), baseIDNew.getId());
item.setBaseID(baseIDNew);
}
Collection<Itemstat> attachedItemstatCollectionNew = new ArrayList<Itemstat>();
for (Itemstat itemstatCollectionNewItemstatToAttach : itemstatCollectionNew) {
itemstatCollectionNewItemstatToAttach = em.getReference(itemstatCollectionNewItemstatToAttach.getClass(), itemstatCollectionNewItemstatToAttach.getItemstatPK());
attachedItemstatCollectionNew.add(itemstatCollectionNewItemstatToAttach);
}
itemstatCollectionNew = attachedItemstatCollectionNew;
item.setItemstatCollection(itemstatCollectionNew);
Collection<Storeditem> attachedStoreditemCollectionNew = new ArrayList<Storeditem>();
for (Storeditem storeditemCollectionNewStoreditemToAttach : storeditemCollectionNew) {
storeditemCollectionNewStoreditemToAttach = em.getReference(storeditemCollectionNewStoreditemToAttach.getClass(), storeditemCollectionNewStoreditemToAttach.getStoreditemPK());
attachedStoreditemCollectionNew.add(storeditemCollectionNewStoreditemToAttach);
}
storeditemCollectionNew = attachedStoreditemCollectionNew;
item.setStoreditemCollection(storeditemCollectionNew);
Collection<Weapon> attachedWeaponCollectionNew = new ArrayList<Weapon>();
for (Weapon weaponCollectionNewWeaponToAttach : weaponCollectionNew) {
weaponCollectionNewWeaponToAttach = em.getReference(weaponCollectionNewWeaponToAttach.getClass(), weaponCollectionNewWeaponToAttach.getId());
attachedWeaponCollectionNew.add(weaponCollectionNewWeaponToAttach);
}
weaponCollectionNew = attachedWeaponCollectionNew;
item.setWeaponCollection(weaponCollectionNew);
Collection<Weapon> attachedWeaponCollection1New = new ArrayList<Weapon>();
for (Weapon weaponCollection1NewWeaponToAttach : weaponCollection1New) {
weaponCollection1NewWeaponToAttach = em.getReference(weaponCollection1NewWeaponToAttach.getClass(), weaponCollection1NewWeaponToAttach.getId());
attachedWeaponCollection1New.add(weaponCollection1NewWeaponToAttach);
}
weaponCollection1New = attachedWeaponCollection1New;
item.setWeaponCollection1(weaponCollection1New);
item = em.merge(item);
if (customizedForOld != null && !customizedForOld.equals(customizedForNew)) {
customizedForOld.getItemCollection().remove(item);
customizedForOld = em.merge(customizedForOld);
}
if (customizedForNew != null && !customizedForNew.equals(customizedForOld)) {
customizedForNew.getItemCollection().add(item);
customizedForNew = em.merge(customizedForNew);
}
if (baseIDOld != null && !baseIDOld.equals(baseIDNew)) {
baseIDOld.getItemCollection().remove(item);
baseIDOld = em.merge(baseIDOld);