Documentation Home
MySQL Cluster API Developer Guide
Download this Manual
PDF (US Ltr) - 5.0Mb
PDF (A4) - 4.9Mb
EPUB - 1.9Mb
HTML Download (TGZ) - 1.9Mb
HTML Download (Zip) - 1.9Mb

4.2.3 Using JPA with MySQL Cluster

ClusterJPA is implemented as a plugin for OpenJPA. The best way to use ClusterJPA is to start with the standard configuration of OpenJPA with JDBC and MySQL Server. Once you know that this configuration works for your application, you can switch to the ClusterJ code path.

In MySQL Cluster NDB 7.1.2 and later, compiling applications for ClusterJPA is the same as compiling them for OpenJPA. To do this, you must have the following jar files in your classpath:

  • openjpa-2.2.2.jar

  • driver-5.1.10.jar (This is the MySQL JDBC driver)

  • geronimo-jta_1.1_spec-1.1.jar

  • geronimo-jpa_3.0_spec-1.0.jar

  • serp-1.13.1.jar

  • commons-lang-2.1.jar

  • commons-collections-3.2.jar

You must also have the OpenJPA jar files to run OpenJPA applications. To run them using ClusterJPA, you also need the clusterj.jar jar file in your classpath, as well as the MySQL Server JDBC connector jar file mysql-connector-j.jar (see Connector/J Installation), and your java.library.path must include the directory where libndbclient can be found.


The requirements for compiling and running OpenJPA applications were slightly different in MySQL Cluster NDB 7.1.1. In that version of MySQL Cluster, in addition to the OpenJPA jar files, clusterj-openjpa.jar was also required for compilation and execution, and the jar files clusterj-core.jar, clusterj-tie.jar, jtie.jar, and ndbjtie.jar were required to run the application; in addition, you needed libndbjtie to be found in your java.library.path.

In MySQL Cluster NDB 7.1.2 and later, these multiple ClusterJPA jar files have been merged into clusterj.jar, and libndbjtie has become part of libndbclient.

You must also update the persistence.xml file, which selects the JPA implementation to be used by the application. The contents of a sample persistence.xml file are shown here (with the relevant portions shown in emphasized text):

<persistence-unit name="personnel" transaction-type="RESOURCE_LOCAL">
    <property name="openjpa.BrokerFactory" value="ndb"/>
    <property name="openjpa.ndb.connectString" value="localhost:1186"/>
    <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/test"/>
    <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
    <property name="openjpa.ConnectionRetainMode" value="transaction"/>

To activate ClusterJPA, the property named openjpa.BrokerFactory must have the value ndb.

The name of the persistence unit is arbitrary; for this example, we have chosen personnel.

User Comments
Sign Up Login You must be logged in to post a comment.