0
votes
try {
        final CHEMRFacilityMedicalEquipment medicalequ = m_chemrFacilityMedicalEquipmentManagementBO
                .findCHEMRFacilityMedicalEquipmentById(id);
        final CHEMRFacilityMedicalEquipment updateMed = new CHEMRFacilityMedicalEquipment();
        if (medicalequ.getMetaStatus() == true) {
            updateMed.setId(medicalequ.getId());
            updateMed.setMetaStatus(false);
            m_chemrFacilityMedicalEquipmentManagementBO
                    .updateCHEMRFacilityMedicalEquipment(updateMed);
            return true;
        }
        return false;
    }

Above is how I am Calling my method in DaOImpl

try {
        m_sessionFactory.getCurrentSession().update(instance);
    } catch (final DataAccessException _e) {
        M_LOG.debug("Update object failed:" + _e.toString());
        throw new CHEMRDAOException(_e.toString());
    } catch (final Exception _e) {
        M_LOG.debug("Update object failed:" + _e.toString());
        throw new CHEMRDAOException(_e.toString());
    }
}

DAO Impimentation

I am trying to update my Object and sending it through the update mehtod to Update data in table. While I am calling update method it returns "a different object with the same identifier value was already associated with the session" Not getting what exactly the problem is.

1
Please provide the full stack trace. And it also looks suspicious that you try to update updateMed.setId. You should not do it. - SternK

1 Answers

0
votes

It could be that your session is currently handling 2 different objects with the same identifier (their ids). For ex.

CHEMRFacilityMedicalEquipment updateMed = new CHEMRFacilityMedicalEquipment();
updateMed.setId(1);
student.setName("Mukesh");

updateMed = new CHEMRFacilityMedicalEquipment();
updateMed.setId(1);
student.setName("Ryan");

Then suppose this statement is invoked

m_sessionFactory.getCurrentSession().save(updateMed );

and while the session for that instance hasn't been closed (committed) yet, the instance is still in a persistant state but somehow your session trying to manage another different instance with a same identifier (id) through another :

m_sessionFactory.getCurrentSession().save(updateMed );

m_sessionFactory.getCurrentSession().close();

Also, these 2 following lines look suspicious to me

 final CHEMRFacilityMedicalEquipment medicalequ = m_chemrFacilityMedicalEquipmentManagementBO
                .findCHEMRFacilityMedicalEquipmentById(id);
 final CHEMRFacilityMedicalEquipment updateMed = new CHEMRFacilityMedicalEquipment();

If could be that your session currently handling those instances with a same identifier (id in this case). I think you can figure it out yourself, because there can't currently much information be extracted from your code.