Hi mmerder,
Thanks for your reply.
deletetion and insertion are not in the same transaction . Please see my code for saving and deletion...
public void save(CrmTeams transientInstance) throws Exception{
ELogger.log("saving CrmTeams instance", DcrmsConstants.INFO);
try {
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
Long teamCode = 1L;
String sqlQuery = "select max(model.teamCode) from CrmTeams model";
Object obj = session.createQuery(sqlQuery).uniqueResult();
Date currentDate = Calendar.getInstance().getTime();
if(obj!=null)
teamCode = (((Long)obj)+1);
transientInstance.setTeamCode(teamCode);
transientInstance.setCreatedDt(currentDate);
for(CrmTeamDept crmTeamDept: transientInstance.getCrmTeamDepts()){
crmTeamDept.getId().setCrmTeams(transientInstance);
crmTeamDept.setCreatedDt(currentDate);
}
for(CrmTeamsBranches crmTeamBranches: transientInstance.getCrmTeamsBrancheses()){
crmTeamBranches.getId().setCrmTeams(transientInstance);
crmTeamBranches.setCreatedDt(currentDate);
}
for(CrmUserTeamDet crmUserTeamDet: transientInstance.getCrmUserTeamDets()){
crmUserTeamDet.getId().setCrmTeams(transientInstance);
crmUserTeamDet.setCreatedDt(currentDate);
}
// CrmTeams crmTeams = (CrmTeams)HibernateSessionFactory.getSession().merge(transientInstance);
//ELogger.log("save successful"+crmTeams.getTeamCode(), DcrmsConstants.INFO);
session.save(transientInstance);
session.flush();
session.evict(transientInstance);
ELogger.log("save successful", DcrmsConstants.INFO);
tx.commit();
session.close();
} catch (Exception ex) {
ELogger.log("save failed", DcrmsConstants.SEVERE);
throw ex;
}
}
public void delete(Vector<Long> values) throws Exception{
ELogger.log("deleting CrmTeams instance", DcrmsConstants.INFO);
try {
Session session = HibernateSessionFactory.getSession();
Transaction tx =session.beginTransaction();
for(Long teamId:values){
CrmTeams obj = (CrmTeams)HibernateSessionFactory.getSession().get(CrmTeams.class, teamId);
ELogger.log("deleting crmTeam with id"+teamId, DcrmsConstants.INFO);
session.delete(obj);
session.flush();
session.evict(obj);
ELogger.log("deleted crmTeam with id"+teamId, DcrmsConstants.INFO);
}
ELogger.log("delete process successful", DcrmsConstants.INFO);
tx.commit();
session.close();
} catch (Exception ex) {
ELogger.log("delete failed", DcrmsConstants.SEVERE);
throw ex;
}
}
Thanks and Regards,
Anish P isaac
|