openxava / documentation / Configuration for AS/400

Configuring your OpenXava application to go against the DB2 of an AS/400 is very simple, basically you have to install the JDBC driver for AS/400 and define correctly the datasource. You don't need to touch any code of your application.

Download the JDBC driver for AS/400

Download the AS/400 driver from here:

You will download a file like this: (the version numbers may vary). Uncompress it to find inside a file called jt400.jar (or so), this last file, the .jar, is the JDBC controller we're going to use.

Create a classpath variable in Eclipse

In order you can connect to AS/400 from Eclipse we're going to declare a classpath variable that points to the AS/400 JDBC driver, so you can use it in any project you need easily. For that, in Eclipse go to Window > Preferences > Java > Build Path > Classpath Variables where you can add the new variable:
You can call the variable AS400_DRIVER instead of DB_DRIVER if your prefer. The path is the path of the JDBC driver, in our case the path of jt400.jar we have just downloaded.

Add the DB_DRIVER variable to your Eclipse project

In the project you're going to use AS/400 you have to add the variable declared above. Click with right mouse button on your project and then choose Java Build Path > Configure Build Path...:project-build-path-eclipse-menu_en.png
Then select the Libraries tab:
With this we have the driver available for the development environment.

Add the JDBC driver to the production Tomcat

Adding the driver in production is much easier. Copy jt400.jar to the lib folder of your Tomcat. Done.

Adjust your datasource definition

For development edit web/META-INF/context.xml of your Eclipse project, and for production edit conf/context.xml of your Tomcat to adjust the datasource to point to AS/400, something like this:
<Resource name="jdbc/MyAppDS" auth="Container"
	maxTotal="100" maxIdle="20" maxWaitMillis="10000"
	username="root" password="ao49fmsk"
The differences are the driverClassName and the url. Obviously, instead of you should put the address of your AS/400, and also put the correct username and password.

Update persistence.xml

You don't need to touch the default persistence unit of persistence.xml (in persistence/META-INF), unless you use hibernate.dialect property in which case just remove hibernate.dialect property. Moreover, you should specify the hibernate.default_schema property for all the persistence units, to indicate in which library of your AS/400 are the tables of your application (unless you use @Table(schema=) in every entity).
Also, you have to modify the junit persistence unit to point to AS/400.
<!-- JUnit AS/400 -->
<persistence-unit name="junit">
<property name="hibernate.default_schema" value="MYLIB"/>
<property name="hibernate.connection.driver_class" value=""/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="ao49fmsk"/> <property name="hibernate.connection.url" value="jdbc:as400:"/> </properties> </persistence-unit>
Adapt the username, password and url to your AS/400 configuration. For the default_schema instead of MYLIB put the AS/400 library for your tables.

Start the journal

In order that your OpenXava application works with AS/400 your tables must support transactions. The simple way to achieve it is creating the library for your tables from SQL using "CREATE COLLECTION MYLIB". Unfortunately most times you work against an AS/400 you have to work with preexisting tables. In this case you have to create a journal for your library, in this way:
Instead  of MYLIB use the name of your library. Afterwards you have to register all the table in the journal, thus:
When in the future you'll create a new table to be used from OpenXava you have to add it to the journal:
If you're not familiar with the AS/400 interface look for help from some AS/400 guru of your company.for this task.