Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
SbiParuse hibParuse = (SbiParuse) aSession.load(SbiParuse.class,
aParameterUse.getUseID());
updateSbiCommonInfo4Update(hibParuse);
hibParuse.setLabel(aParameterUse.getLabel());
hibParuse.setName(aParameterUse.getName());
hibParuse.setDescr(aParameterUse.getDescription());
hibParuse.setSelectionType(aParameterUse.getSelectionType());
hibParuse.setMultivalue(aParameterUse.isMultivalue()? new Integer(1): new Integer(0));
hibParuse.setManualInput(aParameterUse.getManualInput());
SbiLov hibSbiLov = (SbiLov)aSession.load(SbiLov.class, aParameterUse.getIdLov());
//if the lov id is 0 (-1) then the modality is manual input
//insert into the DB a null lov_id
//if the user selected modality is manual input,and before it was a
//lov, we don't need a lov_id and so we can delete it
if(hibSbiLov.getLovId().intValue()== -1 || aParameterUse.getManualInput().intValue() == 1){
hibParuse.setSbiLov(null);
}
else{
hibParuse.setSbiLov(hibSbiLov);}
//hibParuse.setSbiLov(hibSbiLov);
Set parUseDets = hibParuse.getSbiParuseDets();
for (Iterator it = parUseDets.iterator(); it.hasNext();) {
aSession.delete((SbiParuseDet) it.next());
}
Set parUseCks = hibParuse.getSbiParuseCks();
for (Iterator it = parUseCks.iterator(); it.hasNext();) {
aSession.delete((SbiParuseCk) it.next());
}
// Recreate Relations with sbi_paruse_det
List newRoles = aParameterUse.getAssociatedRoles();
SbiParuseDet hibParUseDet = null;
SbiParuseDetId hibParUseDetId = null;
SbiExtRoles tmpExtRole = null;
Set parUseDetsToSave = new HashSet();
for (int i = 0; i < newRoles.size(); i++) {
hibParUseDetId = new SbiParuseDetId();
hibParUseDetId.setSbiParuse(hibParuse);
tmpExtRole = (SbiExtRoles) aSession.load(SbiExtRoles.class,
((Role) newRoles.get(i)).getId());
hibParUseDetId.setSbiExtRoles(tmpExtRole);
hibParUseDet = new SbiParuseDet(hibParUseDetId);
updateSbiCommonInfo4Insert(hibParUseDet);
aSession.save(hibParUseDet);
parUseDetsToSave.add(hibParUseDet);
}
hibParuse.getSbiParuseDets();
hibParuse.setSbiParuseDets(parUseDetsToSave);
// Recreate Relations with sbi_paruse_ck
List newChecks = aParameterUse.getAssociatedChecks();
SbiParuseCk hibParUseCk = null;
SbiParuseCkId hibParUseCkId = null;
SbiChecks tmpCheck = null;
Set parUseCkToSave = new HashSet();
for (int i = 0; i < newChecks.size(); i++) {
hibParUseCkId = new SbiParuseCkId();
hibParUseCkId.setSbiParuse(hibParuse);
tmpCheck = (SbiChecks) aSession.load(SbiChecks.class,
((Check) newChecks.get(i)).getCheckId());
hibParUseCkId.setSbiChecks(tmpCheck);
hibParUseCk = new SbiParuseCk(hibParUseCkId);
aSession.save(hibParUseCk);
parUseCkToSave.add(hibParUseCk);
}
hibParuse.getSbiParuseCks();
hibParuse.setSbiParuseCks(parUseCkToSave);
tx.commit();
}catch(HibernateException he){
logException(he);