Announcement Announcement Module
Collapse
No announcement yet.
To save multiple form copies through Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • To save multiple form copies through Hibernate

    Hi,

    I am using Spring MVC and Hibernate. I have a form with various fields including name, age, address etcc. I would like to save the form multiple times for different user names but the rest of the fields in the form are common to all the users. When I try to use a loop and call saveorupdate of hibernate, only one form gets saved and am not able to save all.
    How do I resolve this problem. Can this be solved via cloning the objects? If so where should I clone the objecst? Is it in a class where i implement the AbstractWizardFormController class? Any help would be greatly appreciable! Is there any other way!

    Thx in advance.

  • #2
    Hi
    Code:
    for (int i=0; i < sampleName.length; i++)
               {
                   String tmp = sampleName[i];                
                   Sample formCopy = (Sample)sample.clone();
                   formCopy.getDetail().setName(tmp);   
                   model.put("form", formCopy); 
                   System.out.println ("Tmp is:" + sample.getName());
                   this.getSampleManager().saveOrUpdateSample(formCopy);  
    }
    I used the above code to save my form multiple times. The problem is all the form gets saved in the same name and name doesn't change. How do I get rids of this!
    And also there seems to be some problem while deleting my records as it says "child record...available"
    Thx.

    Comment


    • #3
      Have you implemented the clone method yourself? Make sure that you clone everything, create a net Detail object etc. Don't reuse anything from the old object. If that happens Hibernate detects it as an already managed object and updates it if it finds any changes.

      I would simply create a new Sample object before saving instead, that ensures that you have a non-managed object.

      Comment


      • #4
        Originally posted by mdeinum View Post
        I would simply create a new Sample object before saving instead, that ensures that you have a non-managed object.
        You could always add a copy constructor to make this a little nicer.
        Last edited by karldmoore; Aug 29th, 2007, 10:28 AM.

        Comment


        • #5
          Yes, thx for ur response. I did try with creating new sample everytime. And I could save records in teh database. but while trying to delete any record I get an exception like this.

          Code:
          The system was unable to delete the samples!
          
          org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [delete from SCSF_QC where QC_ID=?]; ORA-02292: integrity constraint (DEV_SCSF_DB.FKE1EB38C63F64C6E2) violated - child record found
          ; nested exception is java.sql.BatchUpdateException: ORA-02292: integrity constraint (DEV_SCSF_DB.FKE1EB38C63F64C6E2) violated - child record found
          
          java.sql.BatchUpdateException: ORA-02292: integrity constraint (DEV_SCSF_DB.FKE1EB38C63F64C6E2) violated - child record found
          Can anyone suggest why this occurs?

          Comment


          • #6
            I would presume you might have a foreign key reference to another object, but you aren't cascading the delete.
            Last edited by karldmoore; Aug 29th, 2007, 10:28 AM.

            Comment

            Working...
            X