Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Hibernate

You're reading from   Mastering Hibernate Learn how to correctly utilize the most popular Object-Relational Mapping tool for your Enterprise application

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781782175339
Length 204 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Fetching strategy


In Java Persistence API (JPA), you can provide a hint to fetch the data lazily or eagerly using the FetchType implementation. However, some implementations may ignore the lazy strategy and just fetch everything eagerly. Hibernate's default to reduce the memory footprint of your application is FetchType.LAZY.

Tip

The lazy and eager strategies impact the associated entity. When you set fetch strategy of an associated entity to lazy, Hibernate will not fetch the associated entity until you access the associated entity. You must access the associated entity in the same session where you fetched the parent entity; otherwise, you will encounter an exception. On the other hand, the eager fetch strategy forces Hibernate to retrieve the associated entity when the parent entity is fetched.

As mentioned in the previous chapter, Hibernate offers additional fetch modes in addition to the commonly-used JPA fetch types. Here, we will discuss how they are related and provide an explanation...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image