Administration guide > Configure the deployment environment > Configuring cache integration



Configure JPA loaders

A Java™ Persistence API (JPA) Loader is a plug-in implementation that uses JPA to interact with the database.


Before you begin

For more information about how the Java Persistence API (JPA) Loader works, see JPA loaders.


Procedure

  1. Configure the necessary parameters that JPA requires to interact with a database.

    The following parameters are required. These parameters are configured in the JPALoader or JPAEntityLoader bean, and JPATxCallback bean.

    • persistenceUnitName: Specifies the persistence unit name. This parameter is required for two purposes: for creating a JPA EntityManagerFactory, and for locating the JPA entity metadata in the persistence.xml file. This attribute is set on the JPATxCallback bean.

    • JPAPropertyFactory: Specifies the factory to create a persistence property map to override the default persistence properties. This attribute is set on the JPATxCallback bean.

      To set this attribute, Spring style configuration is required.

    • entityClassName: Specifies the entity class name that is required to use JPA methods, such as EntityManager.persist, EntityManager.find, and so on. The JPALoader requires this parameter, but the parameter is optional for JPAEntityLoader. In the case of JPAEntityLoader, if an entityClassName parameter is not configured, the entity class configured in the ObjectGrid entity map is used. Use the same class for the eXtreme Scale EntityManager and for the JPA provider. This attribute is set on the JPALoader or JPAEntityLoader bean.

    • preloadPartition: Specifies the partition at which the map preload is started. If the preload partition is less than zero, or greater than the total number of partitions minus 1, the map preload is not started. The default value is -1, which means the preload does not start by default. This attribute is set on the JPALoader or JPAEntityLoader bean.

    Other than the four JPA parameters to be configured in eXtreme Scale, JPA meta-data are used to retrieve the key from the JPA entities. The JPA metadata can be configured as annotation, or as an orm.xml file specified in the persistence.xml file. It is not part of the eXtreme Scale configuration.

  2. Configure XML files for the JPA configuration.

    To configure a JPALoader or JPAEntityLoader, see Use a Loader

    Configure a JPATxCallback transaction callback along with the loader configuration. The following example is an ObjectGrid XML descriptor file (objectgrid.xml), that has a JPAEntityLoader and JPATxCallback configured:

    configuring a loader including callback - XML example
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
        xmlns="http://ibm.com/ws/objectgrid/config">
       
    <objectGrids>
         
    <objectGrid name="JPAEM" entityMetadataXMLFile="jpaEMD.xml">
           
    <bean id="TransactionCallback" 
               className="com.ibm.websphere.objectgrid.jpa.JPATxCallback">
              
    <property 
                  name="persistenceUnitName" 
                  type="java.lang.String"  
                  value="employeeEMPU" />
          
    </bean>
          
    <backingMap name="Employee" pluginCollectionRef="Employee" />
       
    </objectGrid>
     
    </objectGrids>
    
     
    <backingMapPluginCollections>
       
    <backingMapPluginCollection id="Employee">
           
    <bean id="Loader"
              className="com.ibm.websphere.objectgrid.jpa.JPAEntityLoader">
             
    <property 
                   name="entityClassName" 
                   type="java.lang.String"  
                   value="com.ibm.ws.objectgrid.jpa.test.entity.Employee"/>
           
    </bean>
       
    </backingMapPluginCollection>
     
    </backingMapPluginCollections>
    </objectGridConfig>
    

    To configure a JPAPropertyFactory, you have to use a Spring style configuration. The following is an XML configuration file sample, JPAEM_spring.xml, which configures a Spring bean to be used for eXtreme Scale configurations.

    configuring a loader including JPA property factory - XML example
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:objectgrid="http://www.ibm.com/schema/objectgrid"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
               http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
     
    <objectgrid:JPAEntityLoader id="jpaLoader" 
            entityClassName="com.ibm.ws.objectgrid.jpa.test.entity.Employee"/>
     
    <objectgrid:JPATxCallback id="jpaTxCallback" persistenceUnitName="employeeEMPU" />
    </beans>
    

    The Objectgrid.xml configuration XML file follows. Notice the ObjectGrid name is JPAEM, which matches the ObjectGrid name in the JPAEM_spring.xml Spring configuration file.

    JPAEM loader configuration - XML example
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
     xmlns="http://ibm.com/ws/objectgrid/config">
     
    <objectGrids>
       
    <objectGrid name="JPAEM" entityMetadataXMLFile="jpaEMD.xml">
         
    <bean id="TransactionCallback" 
                className="{spring}jpaTxCallback"/>
           
    <backingMap name="Employee" pluginCollectionRef="Employee" 
                        writeBehind="T4"/>
         
    </objectGrid>
     
    </objectGrids>
        
     
    <backingMapPluginCollections>
       
    <backingMapPluginCollection id="Employee">
          
    <bean id="Loader" className="{spring}jpaLoader" />
       
    </backingMapPluginCollection>
     
    </backingMapPluginCollections>
    </objectGridConfig>
    

    An entity can be annotated with both the JPA annotations and eXtreme Scale entity manager annotations. Each annotation has an XML equivalent that can be used. Thus, eXtreme Scale added the Spring namespace. You can also configure these using the Spring namespace support. For more details about Spring namespace support, see Spring framework integration overview.


Parent topic:

Configure cache integration


Related concepts

JPA Loaders

Program for JPA integration

Configure cache integration


Related tasks

Configure a JPA time-based data updater

Configure HTTP session managers

Configure the dynamic cache provider for WebSphere eXtreme Scale

Monitor eXtreme Scale information in DB2

Troubleshoot loaders

Troubleshoot Java Persistence API (JPA) applications

Troubleshoot loaders

Related reference

JPA cache configuration properties


+

Search Tips   |   Advanced Search