public class Student {
private Long id;
private String name;
private Integer age;
private Set<Book> books = new HashSet<Book>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Set<Book> getBooks() {
return books;
}
public void setBooks(Set<Book> books) {
this.books = books;
}
}
public class Book {
private Long id;
private String name;
private Student owner;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Student getOwner() {
return owner;
}
public void setOwner(Student owner) {
this.owner = owner;
}
}
<class name="Student" table="student">
<id name="id" column="id">
<generator class="identity"></generator>
</id>
<property name="name" column="name" type="string" length="15"></property>
<property name="age" column="age" type="int" length="3"></property>
<set name="books" cascade="all">
<key column="owner"></key>
<one-to-many class="Book"/>
</set>
</class>
<class name="Book" table="book">
<id name="id" column="id">
<generator class="identity"></generator>
</id>
<property name="name" column="name"></property>
<many-to-one name="owner"></many-to-one>
</class>