Show TOC

Procedure documentationLazy-Loading Entities with Single-Valued Relationships Locate this document in the navigation structure

 

The JPA specification defines the EAGER and LAZY fetch types.

The SAP implementation of JPA supports lazy loading of single-valued and collection-valued relationships. For downward compatibility with releases prior to SAP NetWeaver 7.3, lazy loading of single-valued relationships must be enabled explicitly, as described below. Otherwise, such entities are loaded eagerly.

Note Note

Lazy loading is not possible for entities that are part of an inheritance hierarchy.

End of the note.

For more information about fetch types, refer to the Java Persistence API specification.

Prerequisites

You have:

  1. Created a project (for example, JPA, EJB, or Dynamic Web) to store the entities with the Java Persistence facet enabled

    For more information, see Creating JPA Projects in the Developer Studio.

  2. Added the project containing your entities to an Enterprise Application (EAR) project

    For more information, see Assembling Components into Enterprise Applications.

Procedure

Lazy loading of entities with single-valued relationships requires generation of proxy classes for the lazily loadable entities.

  1. In the persistence.xml, enable generation of proxy classes.

    Syntax Syntax

    1. <property name="com.sap.jpa.execution.generate-proxies" value="true" />
    End of the code.
  2. In the application-j2ee-engine.xml, set a reference to the cglib_nodep_22 library.

    Syntax Syntax

    1. <reference reference-type="hard">
      	<reference-target provider-name="sap.com" target-type="library">cglib_nodep_22</reference-target>
      </reference>
    End of the code.

    For more information, see Editing the application-j2ee-engine.xml.

Result

The EntityManager.getReference method now returns lazily loadable instances.