Hibernate ORM is a very complicated framework as one most popular JPA implementer in Java world, explore it thoroughly really takes much time, I want use this article to quickly summarize the basic data load process and major software components.
EntityManager
EntityManager is JPA’s interface, it describes the basic protocols of accessing entity storage. You can manage the entity by using entity identifier like find, merge or remove. Or you can just query the entities by giving query conditions. The EntityManager also provide the references to transaction management that follows JTA.
Application layers manage the EntityManager instance with persistent context configurations, calls method like find to load entity object by using entity id.
Session
Session is the center concept of Hibernate ORM, it manages entity persistent and transaction context and exists throughout every major ORM process. Hibernate defines a very complicated interface classes around concept of Session, like SessionImplementer, TransactionContext, StatelessSession, SessionOwner, the class SessionImpl is the concrete implementation of a Session.
IndentifierLoadAcess
The call sent to EntityManger is forwarded to Session concrete instance which internally takes advantage of IndentifierLoadAcess object to locate the entity persister, each Hibernate entity has a auto generated entity persister which dedicatedly handle all persistence logics for its paired entity.
LoadEvent And LoadEventListener
Hibernate Session wraps the loading behavior as event like process, it builds the LoadEvent object and calls the method fireLoad against the event object to perform the load, the method fireLoad internally lookup LoadEventListener objects to do the actual loading.
LoadEventListener dose 3 types of entity loading, which are:
Entity Loading From DB
Entity Loading From Cache
Entity Proxy Building Up
Entity Persister
Entity persister is the class that performs the actual persistent detailed logics, by default, it internally do actual data loading from DB through Loader objects, it also manages the counterpart entity proxy class that builds data load proxy function like using LazyLoadInitializer to do lazy data loading.
Loader
Loader objects are responsible to communicate with DB source and loading entities from it. Entity Persister uses Loader objects internally to load the final data.