Introduction

This example provides an example of integrating ActiveSpaces Transactions and JPA.

Please see the enclosed source and javadoc for the JPA example.

Overview

The JPA (Java Persistence API) example demonstrates how ActiveSpaces Transactions can be integrated with JPA. The example populates a database with Account information, then manages a cache of ActiveSpaces Transactions Managed Objects to show how an application can use JPA to access data sets that are too large to fit in memory. It uses ActiveSpaces Transactions and JPA transactions together so that updates to the ActiveSpaces Transactions Managed Objects are transactionally applied to the database.

Functional Description

The JPA example does the following:

  1. Creates and populates the account table in the fluencyjpa database.
  2. Instantiates a set of ActiveSpaces Transactions Managed Objects of type Account from the contents of the account table.
  3. Creates, updates, and deletes Account objects on the ActiveSpaces Transactions node, and transactionally applies the modifications to the account table.
  4. Demonstrates how to handle database and ActiveSpaces Transactions errors so that changes are rolled back in the ActiveSpaces Transactions node and in the database.

Database Description

The ActiveSpaces Transactions JPA example will create and use the database fluencyjpa.

The account database table will be created in the fluencyjpa database with the following SQL commands:

create table account (
        accountnumber INT UNSIGNED,
        balance FLOAT)

create unique index account_index on account (accountnumber)

Java Class Description

The following classes are used in the example :

Other utility classes are also included, see the javadoc for a complete description.

Transaction Design

The TransactionManager class manages the JPA resources needed to coordinate ActiveSpaces Transactions transactions with JPA transactions. It internally implements a transaction notifier so that the onCommit() and onRollback() operations commit and rollback the JPA transaction, respectively.

Deployment

Compling the Example

This command will compile the example:

mvn compile

ActiveSpaces Transactions Server

The example can be built and run directly using the ActiveSpaces Transactions development client, or using the ActiveSpaces Transactions Deployment plugin for Maven.

See the documentation for the TIBCO ActiveSpaces Transactions Deployment Maven plugin for more information on configuring the client connectivity.

Database Provider

The example Main class requires the JPA persistence-unit name defined in the persistence.xml as the first argument. This file in turn references a orm.xml mapping-file that maps the example Entity class to the account table definition.

As described above, the example expects to find an account table in the fluencyjpa database. The enclosed POM binds the database setup to the process-test-resources lifecycle phase.

This project uses the deploy:exec target to invoke the main class on a ActiveSpaces Transactions server. To specify the connectivity to the MySQL server, set the properties example.mysqlhost and example.mysqlport, which are referenced in the persistence.xml file.

The following invocation will use the MySQL database server running on the ActiveSpaces Transactions Development Appliance:

mvn -Dexample.mysqlhost=kabira-server.local \
    -Dexample.mysqlport=3306 \
    -Dcom.kabira.fluency.hostName=kabira-server.local \
    -Dcom.kabira.fluency.administrationPort=2000 \
    process-test-resources deploy:exec

To drop the fluencyjpa database, use the clean binding:

mvn -Dexample.mysqlhost=kabira-server.local \
    -Dexample.mysqlport=3306 \
    clean

NOTE: kabira-server.local only works on OS X. Other platforms may use a different name or have to specify an IP address.

Example Output

When the example runs, the contents of the com.kabira.examples.jpa.Account ActiveSpaces Transactions Managed Objects are displayed when accessing, updating, deleting, and created accounts to show that the data is transactionally consistent.

Dependencies

See the Dependencies page for information on the example's dependencies.

For each dependency listed in the Project Dependencies section of the Dependencies page, the example's POM (or parent POM) defines a property specifying the version of the dependency used by the example. These properties can be overridden if there is a need to change the dependency versions used by the example. The names of these properties are of the form com.tibco.groupId.artifactId.version where groupId and artifactId are the group id and artifact id of the dependency. For example, the property named com.tibco.com.tibco.ast.version specifies the version of the dependency with the group id of com.tibco and the artifact id of ast.