You need to map one-to-many relationship between Student and Info entities. In Student mapping you may specify such relationship as following:
Code:
<class name="com.my.domain.Student"
table="STUDENT">
<id
name="id"
column="STUDENT_ID"
type="long">
</id>
... other fields mapping goes here
<set
name="infos"
lazy="false"
cascade="save-update"
sort="unsorted">
<key column="STUDENT_ID" />
<one-to-many class="com.my.domain.Info" />
</set>
....the rest of you mapping file
</class>
In this case, all you need to do is to create Student, set its properties, also create Info object, and add it to infos set:
Code:
Student student = new Student();
student.setName("name");
...
Info info = new Info();
info.setInfoDetails(details);
//obtain set either from Student.getInfos() or create new one
Set infos = new HashSet();
infos.add(info);
//update infos set in Student
student.set(infos);
//now lets' save data
session.save(student);
All nested objects that has primary key value equals to 'unsaved-value' Hibernate will try to persist by inserting new rows in correspondent tables.
This is done by specifying cascade="save-update" in mapping file
Hope this would help to shed the light on Hibernate magic =)
Feel free to ask for details