Search code examples
javajpajakarta-eeeclipselink

How does EclipseLink detect first access to make lazy fetching?


Could anyone explain how EclipseLink detects the first access to field to make lazy fetching? It seems there is some magic and I can't find a way how it is done.

If I understand it right for @OneToMany relation EclipseLink creates intance of org.eclipse.persistence.indirection.IndirectList which controls the access. But I can't understand what EclipseLink does for @ManyToOne relation.


Solution

  • In the ManyToOne or OneToOne case EclipseLink does code enhancement to detect the access. That means instead of the real object you have a proxy in place.

    There are docs:

    https://www.eclipse.org/eclipselink/documentation/2.7/concepts/mappingintro002.htm#CHDJAHDC

    Also interesting to read is the chapter about weaving. https://www.eclipse.org/eclipselink/documentation/2.7/concepts/app_dev005.htm#CCHJEDFH