From CubeiaWiki

Jump to: navigation, search


Firebase JTA Support

Note: This page is relevant for Firebase 1.9 or greater.

Firebase supports JTA for ordinary JDBC data sources and JPA archives. This page will briefly detail the configuration and considerations needed to enable this in games and services.


You need an intermediate understanding of Firebase and transactional services to understand this page.

Data Sources

You can either use a full XA data source or let Firebase emulate XA functionality for you. Full XA support may be expensive, and is not supported by all drivers. In either case you deploy such data sources normally.

XA Data Source Example

This is an example of an XA data source deployment file. Properties passed to the data source are prefixed 'ds.'.

<!DOCTYPE properties SYSTEM "">
  <entry key="tx-type">LOCAL-TX</entry>
  <entry key="xa-data-source">oracle.jdbc.xa.client.OracleXADataSource</entry>
  <entry key="ds.url">jdbc:oracle:thin:@localhost:1521:XE</entry>
  <entry key="ds.password">password1</entry>
  <entry key="ds.user">user1</entry>

Emulated XA Data Source Example

This is an example of an emulated XA data source deployment file. The 'tx-type' property is set, which indicates that this is a normal driver which should be emulated.

<!DOCTYPE properties SYSTEM "">
  <entry key="tx-type">LOCAL-TX</entry>
  <entry key="driver">com.mysql.jdbc.Driver</entry>
  <entry key="url">jdbc:mysql://localhost/test1</entry>
  <entry key="password">password1</entry>
  <entry key="user">user1</entry>

Firebase Configuration

You need to enable JTA for the event execution per type, and you do this in the cluster properties.

# enable JTA for games (tables)

# enable JTA for tournaments (mtt)

# enable JTA for routable services

JTA can be enabled per routable service, but if you want JTA for all executing events, you can enable it globally.

# enable JTA for all events


To enable JTA for JPA you need to configure the persistence archive to use a JTA data source. You do this by pointing out the deployed data source via JNDI. Firebase mounts the data sources under 'comp/env/jdbc', so if your data source is named 'game-db' it will be accessible under this JNDI path:


You also explicitly need to configure the persistence archive to use JTA transactions.

Hibernate JTA Platform

In order for Hibernate to interact with the Firebase JTA system, you should implement a 'jta platform'. This is easy to do by extending the existing abstract base classes in Hibernate. For example:

package test;

import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;

public class FirebaseJtaPlatform extends AbstractJtaPlatform {

	private static final long serialVersionUID = 1135227572057735590L;
	public static final String TM_NAME = "java:comp/env/TransactionManager";
	public static final String UT_NAME = "java:comp/env/UserTransaction";

	protected TransactionManager locateTransactionManager() {
		return (TransactionManager) jndiService().locate( TM_NAME );

	protected UserTransaction locateUserTransaction() {
		return (UserTransaction) jndiService().locate( UT_NAME );

The above class is then configured in the persistence archive like so:

<property name="hibernate.transaction.jta.platform" value="test.FirebaseJtaPlatform" />

Example Hibernate Persistence XML

Below is an example persistence archive configuration for Hibernate, with JTA enabled using a 'game-db' data source (which must be an XA or an emulated data source) for MySQL, and the above Firebase JTA platform.

<persistence xmlns=""
	<persistence-unit name="game-entities" transaction-type="JTA">
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
			<property name="hibernate.transaction.jta.platform" value="test.FirebaseJtaPlatform" />
			<property name="" value="update" />
Personal tools