Thursday, 24 June 2021

Hibernate's @FetchProfile

I came across some hibernate annotations in the source code at work, to be more specific "@FetchProfile". I hadn't seen that one before, so I went onto the Internet.

In my case it was used for Batch jobs, in which all associations were always fetched, and needed to be changed to "EAGER", during the session.

@FetchProfile(name = "STUFF", fetchOverrides = {
@FetchProfile.FetchOverride(entity = Orders.class, association = "customer", mode = FetchMode.JOIN),
})
...
Session session = sessionFactory.getCurrentSession();
session.enableFetchProfile("STUFF");
session.setHibernateFlushMode(FlushMode.MANUAL);

References

A Java geek — Hibernate hard facts - Part 6
https://blog.frankel.ch/hibernate-hard-facts/6/
JBoss Docs Hibernate - 20.1.7. Fetch profiles
https://docs.jboss.org/hibernate/core/3.5/reference/en/html/performance.html#performance-fetching-profiles
JBoss Docs Hibernate Annotations - 2.4.12. Fetch profiles
https://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e3524

No comments:

Post a Comment