-->
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.  [ 2 posts ] 
Author Message
 Post subject: HibernateTemplate.save Problem
PostPosted: Wed Jan 02, 2008 10:09 am 
Newbie

Joined: Wed Jan 02, 2008 7:20 am
Posts: 1
Location: Bangalore
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Mapping documents:

When i am calling HibernateTemplate.save for the following POJO class
'

Code:
@Entity @AccessType("property")
@Table (name="Appointment")
public class Appointment implements Serializable {
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   
   
   private int id;
   private String approvalStatus;
   private Date dateTimeFrom;
   private Date dateTimeTo;
   private User userId;
   private Patient patientId;
   
   public Appointment(){
      userId = new User();
      patientId = new Patient();
   }
   
   /**
    * @return the id
    */
   @Id @GeneratedValue(strategy=GenerationType.AUTO)
   public int getId() {
      return id;
   }
   /**
    * @param id the id to set
    */
   public void setId(int id) {
      this.id = id;
   }
   
   /**
    * @return the approvalStatus
    */
   @Column (length=250)
   public String getApprovalStatus() {
      return approvalStatus;
   }
   /**
    * @param approvalStatus the approvalStatus to set
    */
   public void setApprovalStatus(String approvalStatus) {
      this.approvalStatus = approvalStatus;
   }
   
   /**
    * @return the dateTimeFrom
    */
   @Column (length=26)
   public Date getDateTimeFrom() {
      return dateTimeFrom;
   }
   /**
    * @param dateTimeFrom the dateTimeFrom to set
    */
   public void setDateTimeFrom(Date dateTimeFrom) {
      this.dateTimeFrom = dateTimeFrom;
   }
   
   /**
    * @return the dateTimeTo
    */
   @Column (length=26)
   public Date getDateTimeTo() {
      return dateTimeTo;
   }
   /**
    * @param dateTimeTo the dateTimeTo to set
    */
   public void setDateTimeTo(Date dateTimeTo) {
      this.dateTimeTo = dateTimeTo;
   }
   

   
   
   /**
    * @return the patientId
    */
//   @OneToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="patientID")
   public Patient getPatientId() {
      return patientId;
   }
   /**
    * @param patientId the patientId to set
    */
   public void setPatientId(Patient patientId) {
      this.patientId = patientId;
   }
   
   
   /**
    * @return the userId
    */
//   @OneToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="userId")
   public User getUserId() {
//      System.out.println("Appointment->getUserId , User Object-- " + userId.getUserId() + userId.getClass()  );
      return userId;
   }
   
   /**
    * @param userId the userId to set
    */
   public void setUserId(User userID) {
//      System.out.println("Appointment->setUserId , User Object-- " + userId.getUserId() + userId.getClass()  );
      userId = userID;
//      System.out.println("in appmt : "+ userId .getUserId());
      
   }
   
   public String toString(){
      StringBuffer sb = new StringBuffer("");
        sb.append("\n\n\tAppointmentID - "+ id);
         sb.append("\n\tDoctor        - "+ (userId == null?  "NULL " : userId.getUserId()));
         sb.append("\n\tPatient       - "+ (patientId == null ? "NULL ": patientId.getPatientID() + patientId.getGivenName()));
         sb.append("\n\tFrom Date     - "+ dateTimeFrom);
         sb.append("\n\tTo Date       - "+ dateTimeTo  + "\n");
      return sb.toString();
   }




It is writing following query

Insert query for Appointment Class
Update Query for User class
Update Query for Patient class


I only want to write Insert query for Appointment ...why it is writing update query for other tables ...

Is there any way to avoid this updation ???.....using HibernateTemplate

Please suggest with soln...

Thanks to all!!!



Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: extra updates
PostPosted: Thu Jan 03, 2008 4:42 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Krish,

You specified "cascade=all" on both children objects.
Try experimenting with other cascade settings.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.