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:
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, ...
Get Scala Functional Programming Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.