Workflow Of Hibernate Entity Loading

Pasted_Image_1_21_18__8_24_PM

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.

Pasted_Image_1_21_18__9_23_PM

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.

Pasted_Image_1_21_18__10_05_PM

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.

Pasted_Image_1_21_18__10_07_PM.png

Pasted_Image_1_21_18__10_08_PM.png

LoadEventListener dose 3 types of entity loading, which are:

Pasted_Image_1_21_18__10_38_PM.png

Entity Loading From DB

Pasted_Image_1_21_18__10_47_PM.png

Entity Loading From Cache

Pasted_Image_1_21_18__10_45_PM

Entity Proxy Building Up

Pasted_Image_1_21_18__10_41_PM.png

Pasted_Image_1_21_18__10_43_PM.png

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.

Pasted_Image_1_21_18__10_57_PM.png

Pasted_Image_1_21_18__10_58_PM.png

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.

Pasted_Image_1_21_18__11_00_PM.png

Pasted_Image_1_21_18__11_04_PM.png

Pasted_Image_1_21_18__11_05_PM.png

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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