OOP-ResearchMake It Simpler by Object Oriented Programming

JOnAS EJB server, Enhydra, MySQL, JTA, Java Transaction API, JDBC

This article describes how to use JOnAS EJB server (Enhydra) with MySQL. JOnAS is the implementation of EJB specification Version 1.1, which supports JTA (Java Transaction API). And JOnAS requires JDBC 2.0 compatible driver, including the transaction. But MySQL supports the transaction (BEGIN, COMMIT and ROLLBACK) only in some situation. In the environment where the transaction is not supported, some configuration may be required to work with JOnAS EJB (Enterprise Java Beans) server. But don't worry. MM.MySQL JDBC driver is prepared for JOnAS.


What is JOnAS?

EJB is the core architecture of J2EE. To build up the enterprise-oriented, network-oriented and system-independent Java components, EJB is essential architecture for the serious developer in the world. Since EJB 1.1 specification was released, we have desired some sophisticated EJB compliant server.
And now voilà JOnAS from Evidian.

JOnAS is one of the most powerful EJB server in the world. JOnAS provides us everything we need:

  • Container managed persistence for Entity Beans.
  • Container managed Transaction support.
  • Sophisticated implementation of DataSource(JDBC2)
  • XML based deployment descriptor.
and much more. In addition, JOnAS is build on Java! One of the benefits taken from EJB is that we can be independent from OS and RDB. I believe that the fact of 100%-pure-Java and the sophisticated implementation of DataSource will make us happy.

Go Site Map



Requirement:

MySQL is the world fastest SQL database, which is available for most platform at:

JOnAS supports JTA (Java Transaction API) and requires JDBC 2.0 compatible driver. JDBC 2.0 driver for MySQL is available at: Please download MM.MySQL driver 2.04 or later.

Go Site Map



Transaction support in MySQL:

MySQL Version 3.23.15 or later supports:

  • SET AUTOCOMMIT=1
  • BEGIN
  • COMMIT
  • ROLLBACK
syntaxes. For details, please read the command reference of these syntaxes.
These syntaxes are effective only for transaction safe tables (BDB, INNOBASE or GEMINI).
As for other types of tables, changes will be stored at once independent from the status of AUTOCOMMIT, i.e. the syntaxes above are not effective.

For details, please read the documentation of MySQL.

Go Site Map



Behavior of MM MySQL driver:

0. When the connection is established

If the MySQL server is Version 3.23.15 or later, transactionsSupported is set to true.
And relaxAutoCommit property is set based on the URL for the databse.
For example,

  • jdbc:mysql://localhost/foo?relaxAutoCommit=true

1. setAutoCommit(false)

In case the Version 3.23.15 or later, setAutoCommit(false) executes:

  • SET AUTOCOMMIT=1
If MySQL is older than 3.23.15 and relaxAutoCommit property is NOT set to true, the exception will be thrown.
Or, if relaxAutoCommit property is set to true, this method does nothing.
Note that the relaxAutoCommit property is checked only if the version is older than 3.23.15.

2. commit()

Assuming that setAutoCommit(false) is already invoked without the exception.
If the version is 3.23.15 or later, commit() executes:
  • COMMIT
Otherwise, this method does nothing, regardless of relaxAutoCommit property.

3. rollback()

Assuming that setAutoCommit(false) is already invoked without the exception.
If the version is 3.23.15 or later, rollback() executes:

  • ROLLBACK
Otherwise, this method does nothing, regardless of relaxAutoCommit property.

Go Site Map



JOnAS and MySQL connected by MM.MySQL:

Because JOnAS EJB server requires the JDBC 2.0 compatible driver, setAutoCommit(false) need to be invoked without exception.
When MySQL server is older than 3.23.15, relaxAutoCommit should be set to true to prevent the exception.
In this case, though JOnAS can invoke setAutoCommit(false) without the exception, the subsquent commit() or rollback() does nothing. So, our EJB cannot depend on commit() and rollback() to keep the integrity of the data.
Even if MySQL is 3.23.15 or later, commit() and rollback() is effective only when the table is the type of BDB, INNOBASE or GEMINI.

Go Site Map

Caution!
All the APIs for Servlet/JSP introduced by this web site are now included in Bento framework:
  • Simpler than JSTL or Apache Struts
  • MVC framework by HTML
  • Input validation from CGI FORM
  • Easy user authentication
  • Easy localization (L10n)
To download the APIs and source code examples, please visit the web site of Bento framework.


JBuilder 2007


General Information

For Java Development

Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.


ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved.