-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Row gets deleted automatically
PostPosted: Tue Apr 17, 2007 3:24 pm 
Newbie

Joined: Mon Dec 18, 2006 1:54 am
Posts: 5
I am using Hibernate 3.0 for database MSAccess, with HXTT dialect.

After I insert / update a row in table WorkTaskLog, and try to retrieve this data, it is not found and the added row gets deleted from table.
Either the row completely disappears or all the fields become "#Delete".

Following is my maaping:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.db.vo" default-lazy="false">
<class name="WorkTaskLog" table="T_WORK_TASK_LOG">
<composite-id name="keyWorkTaskLog" class="WorkTaskLogPK">
<key-property name="resourceUserId" column="RESOURCE_USERID" type="string"/>
<key-property name="reportingPeriodId" column="REPORTING_PERIOD_ID" type="long"/>
<key-property name="logTypeCode" column="LOG_TYPE_CODE" type="string"/>
<key-property name="projectCode" column="PROJECT_CODE" type="string"/>
<key-property name="taskCode" column="TASK_CODE" type="string"/>
</composite-id>
<property name="taskAccomplishment" column="TASK_ACCOMPLISHMENT" type="string"/>
<property name="taskStatusCode" column="TASK_STATUS_CODE" type="string"/>
<property name="taskHours" column="TASK_HOURS" type="long"/>
<property name="resourceNames" column="RESOURCE_NAMES" type="string"/>
<property name="planForPeriod" column="PLAN_FOR_PERIOD" type="string"/>
<property name="createdDate" column="ADD_TIMESTAMP" type="date"/>
<property name="createUserId" column="ADD_USERID" type="string"/>
<property name="lastUpdatedDate" column="LAST_UPDATE_TIMESTAMP" type="date"/>
<property name="lastUpdateUserId" column="LAST_UPDATE_USERID" type="string"/>
</class>
</hibernate-mapping>

can you please tell me what can be the reason for this?

_________________
neel


Last edited by imndneel on Fri Apr 27, 2007 4:51 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 8:51 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Please provide some more info like code...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 4:55 pm 
Newbie

Joined: Mon Dec 18, 2006 1:54 am
Posts: 5
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.

_________________
neel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 5:10 pm 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Where's your DAO layer O.o? Your code makes me /sadface. lol

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 5:25 pm 
Newbie

Joined: Mon Dec 18, 2006 1:54 am
Posts: 5
There is of course a DAO layer but I didn't feel it necessary to include the code of it because there was only a few lines of code and then too, i was ultimtely calling the saveOrUpdate method. anyway, here's how I make a call to DAO layer:

Code:
public void createWorkTaskLog(WorkLogBO wrkLog) {
      List lst = new ArrayList();
      WorkTaskLog wrkTaskLog = new WorkTaskLog();
      lst = wrkLog.getTaskActivities();
      for(int cnt=0;cnt<lst.size();cnt++){
         wrkTaskLog = StarsBOVO.getWorkTaskLog(wrkLog,cnt);
         try {
            starsDAO.updateWorkTaskLog(wrkTaskLog);
         } catch (DAOException e) {
            e.printStackTrace();
         }
      }
      
   }


and in DAo layer,

Code:
public void updateWorkTaskLog(WorkTaskLog workTaskLog) throws DAOException {
      if (workTaskLog == null) {
              throw new IllegalArgumentException("Argument workTaskLog may not be null.");
            }
      hibernateDaoSupport.getHibernateTemplate().update(workTaskLog);
          }


is it fine now??

_________________
neel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 5:41 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
adamgibbons wrote:
Your code makes me /sadface. lol


Aw come on now! At least he didn't start his String variable names with 'lpsz'. ;P


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 28, 2007 7:59 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Why not use the Hibernate POJO as your Business Object...? I only use VOs for when I need to pass BOs down to the presentation layer.
Do you get a stack trace on the saveUpdate() call?

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject: Row gets deleted automatically
PostPosted: Wed May 02, 2007 7:09 am 
Newbie

Joined: Mon Dec 18, 2006 1:54 am
Posts: 5
I agree that I could use the VO directly instead of a BO, but well, that's the architecture to be followed.
I am not getting any exceptions after the query execution. Everyting is fine, data is visible in database for some time, and it is automatically deleted when i try to retrieve the same row.

_________________
neel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.