CHAPTER 13 Optimizing fetching and caching Figure 13.3 (Anonymous web server)

CHAPTER 13 Optimizing fetching and caching Figure 13.3 A larger graph fetched eagerly through disabled lazy associations and collections wasn t part of your fetch plan and wasn t initialized before the persistence context was closed. This also happens if you try to access a proxy for example, the User that approved the item. (Note that you can access this proxy two ways: through the approvedBy and bidder references.) With annotations, you switch the FetchType of an entity association or a collection to get the same result: @Entity public class Item { … @ManyToOne(fetch = FetchType.EAGER) private User seller; @OneToMany(fetch = FetchType.EAGER) private Set bids = new HashSet(); … } The FetchType.EAGER provides the same guarantees as lazy=”false” in Hibernate: the associated entity instance must be fetched eagerly, not lazily. We already mentioned that Java Persistence has a different default fetch plan than Hibernate. Although all associations in Hibernate are completely lazy, all @ManyToOne and
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply