com.smartgwt.client.docs
Interface JpaIntegration


public interface JpaIntegration

Integration with JPA

JPA 1.0 and JPA 2.0 annotated entities can be used as Smart GWT data sources. The implementation class for JPA 1.0 is com.isomorphic.jpa.JPADataSource. The implementation class for JPA 2.0 is com.isomorphic.jpa.JPA2DataSource. Both implementations support search with simple Criteria and AdvancedCriteria.
JPA 1.0 and JPA 2.0 implementations use JPQL for data fetch. Note: MySQL DB - 'like' operator is used in a case insensitive manner. Check MySQL Reference Manual :: C.5.5.1 Case Sensitivity in String Searches for more information.

JPA 2.0 implementation uses Metadata API for data source generation from mapped entities.

JPA configuration

JPA configuration should be specified in the persistence.xml file and placed in the /WEB-INF/classes/META-INF directory.
For JPA 2.0 make sure you correctly declare its usage in persistence.xml:

  <persistence
      version="2.0"
      xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  >
  ...
  </persistence>

To use JPA annotated entities you have to create a DataSource with these properties For example:
  <DataSource
      ID="countryDS"
      serverConstructor="com.isomorphic.jpa.JPA2DataSource"
      beanClassName="com.smartgwt.sample.showcase.server.jpa.Country"
  >
      <fields>
  <!-- ... Fields definition ... -->
      </fields>
  </DataSource>
  
Supports field definitions with valueXPath settings. Entity property is accessed (by priority):
  1. valueXPath - supports only simple XPath definitions: "property/subProperty/subSubProperty"
  2. name - most often used when data source field name is the same as entity property name

JPA transactions

JPA provides three mechanisms for transactions: for JEE applications JPA provides integration with JTA (Bean Managed Transactions and Container Managed Transactions); for JSE applications JPA has a native EntityTransaction implementation (Locally Managed Transactions). The transaction mechanism should be configured in the server.properties file by setting property jpa.emfProvider to the fully qualified class name of the provider (implementation of com.isomorphic.jpa.EMFProviderInterface). Smart GWT comes with three implementations:

You can set jpa.emfProvider to your own implementation of com.isomorphic.jpa.EMFProviderInterface if you have specific requirements for transaction handling. EMF will instantiate provided implementation on initialization (static) and will use same instance every time. By using own implementation you can have complete control over creating/using EntityManagerFactory and EntityManager instances. For example: you can create EMFProviderSpring which will look-up EntityManagerFactory and EntityManager instances in Spring and will feed it to JPADataSource.

Additional configurations:

In case you have several persistence units defined in your persistence.xml you can have additional configurations in server.properties file. Additional configurations (prefixed with jpa.) should have name, emfProvider property and other properties required by specified EMF provider implementation. For example:

  jpa.configName.emfProvider: com.isomorphic.jpa.EMFProviderLMT
  jpa.configName.persistenceUnitName: ANOTHER_PERSISTENCE_UNIT_NAME
To use additional JPA configuration you have to set jpaConfig property in data source definition:
  <DataSource
      ID="countryDS"
      serverConstructor="com.isomorphic.jpa.JPA2DataSource"
      beanClassName="com.smartgwt.sample.showcase.server.jpa.Country"
      jpaConfig="configName"
  >
Transaction management:

JPA relations

JPA data sources transparently support JPA relations:

Notes on bidirectional relations:

Implementations are not thread-safe. Datasource acquiring mechanism ensures that a single instance of this class will be used in one thread only.