EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Weaponset persistentWeaponset = em.find(Weaponset.class, weaponset.getWeaponsetPK());
Weapon weaponsOld = persistentWeaponset.getWeapons();
Weapon weaponsNew = weaponset.getWeapons();
Character characterOld = persistentWeaponset.getCharacter();
Character characterNew = weaponset.getCharacter();
if (weaponsNew != null) {
weaponsNew = em.getReference(weaponsNew.getClass(), weaponsNew.getId());
weaponset.setWeapons(weaponsNew);
}
if (characterNew != null) {
characterNew = em.getReference(characterNew.getClass(), characterNew.getId());
weaponset.setCharacter(characterNew);
}
weaponset = em.merge(weaponset);
if (weaponsOld != null && !weaponsOld.equals(weaponsNew)) {
weaponsOld.getWeaponsetCollection().remove(weaponset);
weaponsOld = em.merge(weaponsOld);
}
if (weaponsNew != null && !weaponsNew.equals(weaponsOld)) {
weaponsNew.getWeaponsetCollection().add(weaponset);
weaponsNew = em.merge(weaponsNew);
}
if (characterOld != null && !characterOld.equals(characterNew)) {
characterOld.getWeaponsetCollection().remove(weaponset);
characterOld = em.merge(characterOld);