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