-->
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: How to store compsoite Objects
PostPosted: Thu Oct 04, 2007 5:32 pm 
Newbie

Joined: Thu Aug 23, 2007 9:52 pm
Posts: 9
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


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.