XAP8 == "XAP9NET" || XAP8 == "XAP9" || XAP8 == "XAP9NET")

JPA Support (non-jdbc)

You are viewing an old version (v. 1) of this page.
The latest version is v. 56, last edited on Feb 03, 2012 (view differences | )
view page history | view next version >>

Search XAP 8.0
Searching XAP 8.0 Documentation
Browse XAP 8.0
Offline Documentation

Download latest offline documentation
in HTML format:

xap-8.0-documentation.zip (15MB)



The Java Persistency API (JPA) is a Java programming language framework managing relational data in applications using Java Platform.
GigaSpaces JPA implementation is based on OpenJPA 2.0.0.


Standard JPA configuration

Here's an example of a persistence.xml configuration file:

<persistence-unit name="gigaspaces" transaction-type="RESOURCE_LOCAL">
           <property name="openjpa.BrokerFactory" value="abstractstore"/>
           <property name="openjpa.abstractstore.AbstractStoreManager" value="org.openspaces.jpa.StoreManager"/>
           <property name="openjpa.LockManager" value="none"/>
    	   <property name="openjpa.ConnectionURL" value="/./jpaSpace"/>

An alternative for using the "ConnectionURL" property is to specify a space instance when creating the entity manager factory through the "ConnectionFactory" property:

GigaSpace gigaSpace;
Properties properties = new Properties();
properties.put("ConnectionFactory", gigaSpace.getSpace());
EntityManagerFactory emf = Persistence.createEntityManagerFactory("gs_store", properties);

Configuration using Spring

It is possible to inject either an EntityManager or EntityManager factory using Spring.
In the following example we'll see how to inject a space and an EntityManagerFactory.
In the following Spring xml configuration file we'll declare a space, an entity manager factory, a transaction manager and a JPA service bean:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- space definition -->
        <os-core:space id="space" url="/./jpaSpace" lookup-groups="test"/>

        <!-- entity manager factory definition -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="spring"/>
		<property name="jpaVendorAdapter">
			<bean class="org.openspaces.jpa.OpenSpacesJpaVendorAdapter">
				<property name="space" ref="space"/>

        <!-- transaction manager definition -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />

        <!-- support annotations -->
	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />	
	<tx:annotation-driven transaction-manager="transactionManager"/>

        <!-- our JPA service definition -->
	<bean id="jpaService" class="org.openspaces.jpa.JpaService" />

Here's our JpaService implementation:

public class JpaService {
    private EntityManager em;
    public JpaService() {
    public void persistObject() {            

Entities Enhancement

JPA entities are monitored in runtime and therefore requires enhancement.
Information regarding how to enhance your entities can be found on OpenJPA's Entity Enhancement page.

JPA Entities

There are a few restrictions when creating a JPA entity for usage with GigaSpaces:

  1. JPA annotations are only allowed for getters (not fields).
  2. @Id annotated getter should also have a @SpaceId annotation.
  3. Other GigaSpaces annotations such as @SpaceRouting are allowed.

Here's an example of a JPA Owner entity:

public class Owner {
    private Integer id;
    private String name;
    private List<Pet> pets;    
    public Owner() {
    public Owner(Integer id, String name, List<Pet> pets) {
        this.id = id;
        this.name = name;
        this.pets = pets;
    public Integer getId() {
        return id;
    public void setId(Integer id) {
        this.id = id;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
    @OneToMany(cascade = CascadeType.ALL)
    public List<Pet> getPets() {
        return pets;
    public void setPets(List<Pet> pets) {
        this.pets = pets;

JPA Query Language (JPQL)

Unsupported features of JPA