Un cargador Java Persistence API (JPA) es una implementación de plug-in que utiliza JPA para interactuar con la base de datos.
Los siguientes parámetros son necesarios. Estos parámetros se configuran en el bean JPALoader o JPAEntityLoader, y en el bean JPATxCallback.
Aparte de los cuatro parámetros JPA que se configuran en eXtreme Scale, se utilizan metadatos JPA para recuperar la clave de las entidades JPA. Los metadatos JPA se pueden configurar como una anotación, o como un archivo orm.xml especificado en el archivo persistence.xml. No forman parte de la configuración de eXtreme Scale.
Para configurar un JPALoader o JPAEntityLoader, consulte Plug-ins para la comunicación con bases de datos.
Configure una devolución de llamada de transacción JPATxCallback junto con la configuración del cargador. El ejemplo siguiente es un archivo de descriptor XML de ObjectGrid (objectgrid.xml), que tiene configurado un JPAEntityLoader y JPATxCallback:
configuración de un cargador incluida la devolución de llamada - ejemplo XML
<?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>
Si desea configurar un JPAPropertyFactory, debe utilizar una configuración de estilo Spring. A continuación se muestra un ejemplo de archivo de configuración XML, JPAEM_spring.xml, que configura un bean Spring que se utilizará para configuraciones eXtreme Scale.
configuración de un cargador incluida la fábrica de propiedades JPA - ejemplo XML
<?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>
Sigue el archivo XML de configuración de Objectgrid.xml. Tenga en cuenta que el nombre de ObjectGrid es JPAEM, que coincide con el nombre de ObjectGrid en el archivo de configuración de Spring JPAEM_spring.xml.
Configuración del cargador JPAEM - ejemplo de XML
<?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>
Se puede anotar una entidad con las anotaciones JPA y, también, las anotaciones del gestor de entidades eXtreme Scale. Cada anotación tiene un XML equivalente que puede utilizarse. Por lo tanto, eXtreme Scale se añade al espacio de nombres de Spring. También puede configurarlas mediante el uso del soporte de espacio de nombres Spring. Para obtener más información, consulte Visión general de la infraestructura Spring.