-->
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.  [ 1 post ] 
Author Message
 Post subject: Removing and Updating Childs in HashSet
PostPosted: Tue Mar 14, 2006 3:32 am 
Newbie

Joined: Tue Mar 14, 2006 2:36 am
Posts: 1
HI all,

I am getting Constraint Violations while doing this.

1. I am retriving Master Object from DB
2. Removing Childs from the Master Object
3. Adding New child objects To master by using HashSet.
4. Updating the Master.

While Updating the Master I am getting the Constraint Violation Error in Child Object.

Here is the Coding

Master POJO
Code:
/**
* @hibernate.class table="JOB"
*
*/
public class Job extends BaseObject {
   private Integer version;
   private Long jobId;

   private String jobNo;
   private String jobType;
   private String jobSts;
   private String blNo;

   private Set jobDocSums=new HashSet();
   private Set jobDocs=new HashSet();



   /**
    * @return Returns the version.
    * @hibernate.version column="VERSION"
    */
   public Integer getVersion() {
      return version;
   }
   /**
    * @param version The version to set.
    */
   public void setVersion(Integer version) {
      this.version = version;
   }
   /**
    * @return Returns the blNo.
    * @hibernate.property
    * @hibernate.column name="BL_NO" length="60"
    */
   public String getBlNo() {
      return blNo;
   }

   /**
    * @return Returns the jobId.
    * @hibernate.id column="JOB_ID"
    * generator-class="increment" unsaved-value="null"
    */
   public Long getJobId() {
      return jobId;
   }
   /**
    * @return Returns the jobNo.
    * @hibernate.property
    * @hibernate.column name="JOB_NO" not-null="true" length="60" unique-key="JOB_UK"
    */
   public String getJobNo() {
      return jobNo;
   }
   /**
    * @return Returns the jobSts.
    * @hibernate.property
    * @hibernate.column name="JOB_STS" length="1"
    */
   public String getJobSts() {
      return jobSts;
   }
   /**
    * @return Returns the jobType.
    * @hibernate.property
    * @hibernate.column name="JOB_TYPE" length="60" not-null="true"
    */
   public String getJobType() {
      return jobType;
   }


   /**
    * @return Returns the jobDocs.
    * @hibernate.set inverse = "true" cascade = "all-delete-orphan"
     * @hibernate.collection-key column = "JOB_ID"
     * @hibernate.collection-one-to-many class ="model.JobDoc"
    */
   public Set getJobDocs() {
      return jobDocs;
   }
   /**
    * @param jobDocs The jobDocs to set.
    */
   public void setJobDocs(Set jobDocs) {
      this.jobDocs = jobDocs;
   }
   public void addJobDocs(JobDoc jobDoc)
   {
      jobDoc.setJob(this);
      jobDocs.add(jobDoc);
   }
   /**
    * @return Returns the jobDocSums.
    * @hibernate.set inverse = "true" cascade = "all-delete-orphan"
     * @hibernate.collection-key column = "JOB_ID"
     * @hibernate.collection-one-to-many class ="model.JobDocSum"
    */
   public Set getJobDocSums() {
      return jobDocSums;
   }
   public void setJobDocSums(Set jobDocSums) {
      this.jobDocSums = jobDocSums;
   }
   public void addJobDocSum(JobDocSum jobDocSum)
   {
      jobDocSum.setJob(this);
      jobDocSums.add(jobDocSum);
   }

}


Child POJO
Code:
/**
*
* @hibernate.class table="JOB_DOC"
*/

public class JobDoc extends BaseObject {

   private Long jobDocId;
   private String jobDocType;
   private String jobDocRefNo;
   private Integer version;

   private Job job;


   /**
    * @return Returns the jobDocId.
    * @hibernate.id column="JOB_DOC_ID"
    * generator-class="increment" unsaved-value="null"
    */
   public Long getJobDocId() {
      return jobDocId;
   }
   /**
    * @param jobDocId The jobDocId to set.
    */
   public void setJobDocId(Long jobDocId) {
      this.jobDocId = jobDocId;
   }
   /**
    * @return Returns the jobDocRefNo.
    * @hibernate.property
    * @hibernate.column name="JOB_DOC_REF_NO"
    */
   public String getJobDocRefNo() {
      return jobDocRefNo;
   }
   /**
    * @param jobDocRefNo The jobDocRefNo to set.
    */
   public void setJobDocRefNo(String jobDocRefNo) {
      this.jobDocRefNo = jobDocRefNo;
   }
   /**
    * @return Returns the jobDocType.
    * @hibernate.property
    * @hibernate.column name="JOB_DOC_TYPE"
    */
   public String getJobDocType() {
      return jobDocType;
   }
   /**
    * @param jobDocType The jobDocType to set.
    */
   public void setJobDocType(String jobDocType) {
      this.jobDocType = jobDocType;
   }
   /**
    * @return Returns the job.
    * @hibernate.many-to-one column="JOB_ID"
    * class="model.Job"
    */
   public Job getJob() {
      return job;
   }

   /**
    * @param trumanJob The job to set.
    */
   public void setJob(Job job) {
      this.job = job;
   }

   /**
    * @return Returns the version.
    * @hibernate.version column="VERSION"
    */
   public Integer getVersion() {
      return version;
   }
   /**
    * @param version The version to set.
    */
   public void setVersion(Integer version) {
      this.version = version;
   }
}


My ManagerImpl method
Code:
public class InterfaceManagerImpl extends BaseManager implements InterfaceManager
{
   private Log log = LogFactory.getLog(InterfaceManagerImpl.class);

   private JobManager jobManager;

   public void setJobManager(JobManager jobManager)
   {
      this.jobManager = jobManager;
   }


   public Long updateDocs(String excelFile, String sheetName,String userId) {

      Job jobObj = null;
      int count = 0;
      try
      {
         Workbook w = Workbook.getWorkbook(new File(excelFile));
         if (sheetName == null)
            sheetName = "Sheet1";
         if (sheetName.equals(""))
            sheetName = "Sheet1";
         Sheet s = w.getSheet(sheetName);

         Cell[] row = null;

         String blNo = "";
         String blpInCd = "";

         if(s != null)
         {
            log.info("NO OF ROWS :"+s.getRows());
            for (int i = 1; i < s.getRows(); i++)
            {
               row = s.getRow(i);

               blNo = getDo(row);
               blpInCd = getBlpInCd(row);

                if(!blNo.equals(""))
               {
                  jobObj = new Job();
                  jobObj.setBlNo(blNo);
                  jobObj = (Job)jobManager.getJob(jobObj);
                  if(jobObj != null)
                  {
                     if (jobObj.getJobDocs() != null)jobObj.getJobDocs().removeAll(jobObj.getJobDocs());

                     JobDoc docObj = new JobDoc();
                     JobDocSum docSum = new JobDocSum();
                     if (!blpInCd.equals(""))
                     {
                        docObj = new JobDoc();
                         docObj.setJobDocType("BLP");
                         docObj.setJobDocRefNo(blpInCd);
                         jobObj.addJobDocs(docObj);
                     }

                     jobManager.updateJob(jobObj);
                     count++;
                  }
               }
            }
         }
      } catch (Exception e)
      {
         e.printStackTrace();
         return new Long(0);
      }
      return new Long(count);
   }


}


This is My Service.xml file
Code:
<bean id="interfaceManagerTarget" class="job.service.InterfaceManagerImpl" singleton="true" >
    <property name="jobManager"><ref local="jobManager"/></property>
   
</bean>
<bean id="interfaceManager"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
    <ref local="transactionManager"/>
  </property>
  <property name="target">
    <ref local="interfaceManagerTarget"/>
  </property>
  <property name="transactionAttributes">
    <props>
      <prop key="updateDocs">PROPAGATION_REQUIRED</prop>
      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
  </property>
</bean>



I am getting the Unique Constraint Viloation exception Pls give me some Idea.........


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

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.