Workflow Of Hibernate Entity Loading


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 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 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.



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 objects are responsible to communicate with DB source and loading entities from it. Entity Persister uses Loader objects internally to load the final data.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s