openxava / documentation / Configuration for MySQL

If you're using an OpenXava version older than 7.0 look at the old instructions
Configuring your OpenXava application to go against MySQL is very simple, basically you have to add a dependency to the JDBC driver for MySQL in your project and define correctly the datasource. You don't need to touch any code of your application.
We assume you have already installed and running MySQL.
Follow the next video to setting up MySQL in OpenXava project:
Follow this video
If you don't like videos, follow the instructions below.

Add JDBC driver for MySQL 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>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.3.0</version>
</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 MySQL, something like this:
<Resource name="jdbc/MyAppDS" auth="Container"
    type="javax.sql.DataSource"
    maxTotal="100" maxIdle="20" maxWaitMillis="10000"
    username="root" password="ao49fmsk"
    driverClassName="com.mysql.cj.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/myappdb"/>
The differences are the driverClassName and the url. Obviously, instead of localhost you should put the address of the server that hosts MySQL and instead of myappdb the name of your database.. 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.

Create schema manually

Hibernate version 5.6 has a bug that no longer creates schema automatically, thus neither the tables. If you encounter this error, the solution is create manually the schema in the database by executing the statement:
CREATE DATABASE myappdb;
This way, the tables will be created once the application is started.

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 MySQL database. If it fails, verify that your database server is up, that the user and password in context.xml are correct, that the server IP is correct. Also verify that the user has rights to create databases and tables (if you want to use the automatic schema generation of OpenXava, not needed if the tables already exist).

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.