Вы находитесь на странице: 1из 2

System.out.println(">>>>>>>>>>>>>>>>>>>>> userData.getId()"+userData.get(0).

get
Id());
for (int i = 0; i < userData.size(); i++) {
LkpDecisionUserData lkpDecisionUserData = userData.get(i);
System.out.println("lkpDecisionUserData ID = " + lkpDecisionUserDat
a.getId().getLkpDecisionUserDataId());
}
if (userData.get(0).getId() == null) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>I will save the new reco
rd");
//new record
//----------- will save the instance -----------------
// System.out.println("Before Boooooooooooooooooooooooooooooom");
System.out.println(">>>>Find EcmChemises , EcmCorrespondences");
ecmDecisions.setEcmChemises(chemisesHome.findById(ecmChemisesId));
ecmDecisions.setEcmCorrespondences(correspondencesHome.findById(ecmC
orrespondencesId));
// System.out.println("After Boooooooooooooooooooooooooooooom");
//--- setting not null values ----------------
ext.setDecPeriod(ecmDecisionsExtPeriod);
for (int i = 0; i < userData.size(); i++) {
userData.get(i).setId(new LkpDecisionUserDataId(i+"", ecmDecisions
.getEcmDecisionsId()));

}
try {
//--save the parent
decisionsHome.persist(ecmDecisions);
//-- save the sub of the parent
extHome.persist(ext);
//-- save sub child
decisionsTravel.setEcmDecisionsExt(ext);
//--save the user data entity
for (int i = 0; i < userData.size(); i++) {
userData.get(i).setEcmDecisionsExt(ext);
userDataHome.persist(userData.get(i));
}
//-- save the decision travel entity
decisionsTravelHome.persist(decisionsTravel);
System.out.println(">>>>>>>>>>>>>>>>>>>>> Before commit");
tx.commit();
System.out.println(">>>>>>>>>>>>>>>>>>>>> Items should be saved
:)");
} catch (Exception ex) {
tx.rollback();
ex.printStackTrace();
throw ex;
} finally {
if (session != null) {
session.close();
}
}
} else {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> I will update id not nu
ll");
System.out.println(">>>>Find EcmChemises , EcmCorrespondences");
ecmDecisions.setEcmChemises(chemisesHome.findById(1l));
ecmDecisions.setEcmCorrespondences(correspondencesHome.findById(1l))
;
// System.out.println("After Boooooooooooooooooooooooooooooom");
//--- setting not null values ----------------
ext.setDecPeriod("1");
for (int i = 0; i < userData.size(); i++) {
userData.get(i).setId(new LkpDecisionUserDataId(i+"", ecmDecisions
.getEcmDecisionsId()));

try {
//--save the parent
decisionsHome.merge(ecmDecisions);
//-- save the sub of the parent
extHome.merge(ext);
//-- save sub child
for (int i = 0; i < userData.size(); i++) {
userData.get(i).setEcmDecisionsExt(ext);
userDataHome.merge(userData.get(i));
}
decisionsTravel.setEcmDecisionsExt(ext);
//--save the user data entity
//-- save the decision travel entity
decisionsTravelHome.merge(decisionsTravel);
System.out.println(">>>>>>>>>>>>>>>>>>>>> Before commit Updates
>>>>>>>>>>>");
tx.commit();
System.out.println(">>>>>>>>>>>>>>>>>>>>> Items should be Update
d >>>>>>>>>>>>>>>> :)");
} catch (Exception ex) {
tx.rollback();
ex.printStackTrace();
throw ex;
} finally {
if (session != null) {
session.close();
}
}
}