openxava / documentation / Configuration for AS/400

If you're using an OpenXava version older than 7.0 look at the old instructions
Configuring your OpenXava application to go against DB2 of an AS/400 is very simple, basically you have to add a dependency to the JDBC driver for AS/400 in your project and define correctly the datasource. You don't need to touch any code of your application.

Add JDBC driver for AS/400 to your project

Edit the pom.xml file in the root of your project, there add the next dependency inside the <dependencies> part:

<dependency>
    <groupId>net.sf.jt400</groupId>
    <artifactId>jt400</artifactId>
    <version>20.0.7</version>
    <classifier>java8</classifier>
</dependency>
Maybe the above code is already in your pom.xml but commented, in that case just uncomment it.

Adjust your datasource definition

Edit src/main/webapp/META-INF/context.xml of your project to adjust the datasource to point to AS/400, something like this:
<Resource name="jdbc/MyAppDS" auth="Container"
    type="javax.sql.DataSource"
    maxTotal="100" maxIdle="20" maxWaitMillis="10000"
    username="java" password="ao49fmsk"
    driverClassName="com.ibm.as400.access.AS400JDBCDriver"
    url="jdbc:as400:192.168.1.8/mylib"/>
The differences are the driverClassName and the url. Obviously, instead of 192.168.1.8 you should put the IP of your AS/400 and instead of mylib put the name of the library where your tables are in your AS/400. Also put the correct username and password. Maybe the above code is already in your context.xml but commented, in that case just uncomment it. Don't forget to comment or remove the datasource for HSQLDB (the default one when you create a new OpenXava project), only one datasource (with the same name) should be active.

Update persistence.xml

You don't need to touch the default persistence unit of persistence.xml (in src/main/resources/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).

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:
CRTJRNRCV JRNRCV(MYLIB/MYRCV) THRESHOLD(5000)
CRTJRN JRN(MYLIB/MYJRN) JRNRCV(MYLIB/MYRCV) MNGRCV(*SYSTEM)
CHGJRN JRN(MYLIB/MYJRN) JRNRCV(*GEN) DLTRCV(*YES)
Instead  of MYLIB use the name of your library. Afterwards you have to register all the table in the journal, thus:
STRJRNPF FILE(MYLIB/*ALL) JRN(MYLIB/MYJRN) IMAGES(*BOTH) OMTJRNE(*OPNCLO)
When in the future you'll create a new table to be used from OpenXava you have to add it to the journal:
STRJRNPF FILE(MYLIB/MYTABLE) JRN(MYLIB/MYJRN)
If you're not familiar with the AS/400 interface look for help from some AS/400 guru of your company for this task.

Rebuild your project

After the changes you have to rebuild your project. In OpenXava Studio click with right mouse button on your project an choose Run As > Maven install, thus:

Or if you have Maven installed in your computer and you prefer to use command line:

$ cd myapp
$ mvn install

Optimization note: Instead of a mvn install, that do a complete Maven build, you can use mvn war:exploded, enough to apply the above changes for development. You can run mvn war:exploded from OpenXava Studio with Run As > Maven build... and typing war:exploded for goal.

Run your application

Run your application, it should work nicely against your IBM i. If it fails, verify that the user and password in context.xml are correct, that the server IP is correct. Also verify that the journal has been created and the tables added to it, as explained above.

If it still fails ask us in the OpenXava Help forum. Include the content of your persistence.xml, context.xml (remove the passwords) and specially the stacktrace produced, you can find the trace in the Console tab of OpenXava Studio.

Performance problem with Windows Server

If your Java application is running on a Windows Server and you are experiencing performance issues, it may not necessarily be an issue with the AS/400 but rather a network configuration problem on the Windows Server. Don't worry, the problem is easy to fix, simply add the parameter tcp no delay=true to the database connection URL. That is, the definition of the data source in the context.xml could be:

<Resource name="jdbc/MyAppDS" auth="Container"
    type="javax.sql.DataSource"
    maxTotal="100" maxIdle="20" maxWaitMillis="10000"
    username="java" password="ao49fmsk"
    driverClassName="com.ibm.as400.access.AS400JDBCDriver"
    url="jdbc:as400:192.168.1.8/mylib;tcp no delay=true"/>

Note the tcp no delay=true at the end of the URL.