I am having a POJO class called WorkTaskLog.java whose instace I am creating and populating it with the data in my business object. then I am calling the saveOrUpdate method on this instance.
My Business Object is
Code:
public class WorkLogBO {
private String resoruceId;
private String projectId;
private String reportingPeriodId;
private String logRemark;
private String logStatus;
private String resourceNames;
private List taskActivities;
private List resHourLogBOs;
private List SDLCActivity;
private String addUserId;
private Date addedOnDate;
private String lastUpdateId;
private Date lastUpdateDate;
// getter and setter of the above fields
}
then I convert it to Hibernate POJO class
Code:
public static WorkLog wrkLogBoToVo(WorkLogBO objWorkLogBo) throws Exception{
WorkLog objWrkLog = new WorkLog();
WorkLogPK objWrkLogPk = new WorkLogPK();
ResourceHourLogBO objResHrLogBo = new ResourceHourLogBO();
List lstResHrLog = new ArrayList();
Iterator itr = null;
long totalHrs = 0;
long totalBillHrs = 0;
long totalNonBillHrs = 0;
long totalRegHrs = 0;
long totalExtraHrs = 0;
long totalTrnBillHrs = 0;
long totalVacHrs = 0;
long totalCompHrs = 0;
long totalHolHrs = 0;
long totalTrnNonBillHrs = 0;
if(objWorkLogBo!=null){
try{
if(objWorkLogBo.getResoruceId()!=null){
objWrkLogPk.setResourceUserId(objWorkLogBo.getResoruceId());
}
}catch(Exception e){throw new Exception("Exception while setting resourceuserid in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getReportingPeriodId()!=null){
objWrkLogPk.setReportingPeriodId(Long.parseLong(objWorkLogBo.getReportingPeriodId()));
}
}catch(Exception e){throw new Exception("Exception while setting reportingperiodid in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getProjectId()!=null){
objWrkLogPk.setProjectCode(objWorkLogBo.getProjectId());
}
}catch(Exception e){throw new Exception("Exception while setting projectcode in StarsBOVO.wrkLogBoToVo : "+e);}
objWrkLogPk.setLogTypeCode("STATUS");
objWrkLog.setKeyWorkLog(objWrkLogPk);
try{
if(objWorkLogBo.getLogRemark()!=null){
objWrkLog.setLogRemark(objWorkLogBo.getLogRemark());
}
}catch(Exception e){throw new Exception("Exception while setting logremark in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getLogStatus() == null || objWorkLogBo.getLogStatus().equals("")){
objWrkLog.setLogStatusCode("OPEN");
}
//openOrNot to be kept true in case of submitting,
//when there's no change to be made to status, openOrNot is false
else if(objWorkLogBo.getLogStatus() != null){
objWrkLog.setLogStatusCode(objWorkLogBo.getLogStatus());
}
}catch(Exception e){throw new Exception("Exception while setting logstatus in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getAddedOnDate()!=null){
objWrkLog.setCreatedDate(objWorkLogBo.getAddedOnDate());
}
}catch(Exception e){throw new Exception("Exception while setting createddate in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getAddUserId()!=null){
objWrkLog.setCreateUserId(objWorkLogBo.getAddUserId());
}
}catch(Exception e){throw new Exception("Exception while setting createuserid in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getLastUpdateDate()!=null){
objWrkLog.setLastUpdatedDate(objWorkLogBo.getLastUpdateDate());
}
}catch(Exception e){throw new Exception("Exception while setting createuserid in StarsBOVO.wrkLogBoToVo : "+e);}
try{
if(objWorkLogBo.getLastUpdateId()!=null){
objWrkLog.setLastUpdateUserId(objWorkLogBo.getLastUpdateId());
}
}catch(Exception e){throw new Exception("Exception while setting createuserid in StarsBOVO.wrkLogBoToVo : "+e);}
//setting the resource hour log data
lstResHrLog = objWorkLogBo.getResHourLogBOs();
itr = lstResHrLog.iterator();
while(itr.hasNext()){
objResHrLogBo = (ResourceHourLogBO)itr.next();
totalRegHrs += objResHrLogBo.getRegularHours();
totalExtraHrs += objResHrLogBo.getExtraHours();
totalTrnBillHrs += objResHrLogBo.getTrainingBillableHours();
totalVacHrs += objResHrLogBo.getVacationHours();
totalHolHrs += objResHrLogBo.getHolidayHours();
totalCompHrs += objResHrLogBo.getCompOffHours();
totalTrnNonBillHrs += objResHrLogBo.getTrainingNonBillableHours();
}
try{
objWrkLog.setTotalRegularHours(totalRegHrs);
objWrkLog.setTotalExtraHours(totalExtraHrs);
objWrkLog.setTotalTrainingBillableHours(totalTrnBillHrs);
objWrkLog.setTotalCompOffHours(totalCompHrs);
objWrkLog.setTotalHolidayHours(totalHolHrs);
objWrkLog.setTotalVacationHours(totalVacHrs);
objWrkLog.setTotalTrainingNonBillableHours(totalTrnNonBillHrs);
objWrkLog.setTotalBillableHours(totalRegHrs + totalExtraHrs + totalTrnBillHrs);
objWrkLog.setTotalNonBillableHours(totalCompHrs + totalHolHrs + totalVacHrs + totalTrnNonBillHrs);
objWrkLog.setTotalHours(totalRegHrs + totalExtraHrs + totalTrnBillHrs +
totalCompHrs + totalHolHrs + totalVacHrs + totalTrnNonBillHrs);
}catch(Exception e){throw new Exception("Exception while setting totalhours in StarsBOVO.wrkLogBoToVo : "+e);}
}
return objWrkLog;
}
then I take the objWorkLog (Hibernate POJO object) and call
Code:
hibernateDaoSupport.getHibernateTemplate().saveOrUpdate(objWrkLog);
I hope I 've provided what you asked for.