December 2015
Intermediate to advanced
298 pages
5h 30m
English
Hibernate exposes persistence-related database access via an object API. A Java class is mapped to a database table. A parent having many children is mapped as shown in the following code:
@Entity
public class Parent {
…
@OneToMany(mappedBy = "parent")
private Set<Child> children;
…
}
@Entity
public class Child {
…
@ManyToOne
@JoinColumn(name = "parent_id")
private Parent parent;
…
}This maps the following table structure:

Figure 4.3: Proxying in Hibernate
The children are, by default, lazy loaded. This holds true for any mapped members that are collections. You may not need them all the time you load the parent. If you do, ...
Read now
Unlock full access