Code:
@Entity
@Table(name="Teacher")
public class Teacher implements Serializable {
@Id
@Column(name="id")
private int id;
@Column(name="name")
private String name;
@OneToMany
@JoinColumn(name="id")
private List<Student> student;
//getter/setters
}
/////////////////////////////
@Entity
@Table(name="Student")
public class Student implements Serializable {
@Id
@Column(name="id")
private int id;
@Column(name="stuname")
private String StudentName;
//getter/setters
}
And to store object, I am using
Teacher t1 = new Teacher();
t1.setId(10);
t1.setName("from hibernate");
Student s1 = new Student();
s1.setId(10);
s1.setStudentName("Student from hibernate");
List<Student> l = new ArrayList<Student>();
l.add(s1);
t1.setStudent(l);
getHibernateTemplate().save(t1);
The query generated by hibernate is
Hibernate: insert into Teacher (name, sex, id) values (?, ?, ?)
Hibernate: update Student set id=? where id=?
Why am I getting update for student, this is a new object, Can any body please help me