O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hibernate's lazy loading

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:

Hibernate's lazy loading

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required