Saturday, December 27, 2008

Configuring OpenXava with MySql

Recently I started learning OpenXava and I wanted to configure OpenXava with MySQL. Lack of documentation on OpenXava 3.1 and all of them were configured to HSQL database, took me a long time to configure it to MySQL. So I thought of sharing my findings with others.

The intention of this post is not to give a step by step guide for OpenXava (which I’ll do in some other post) but to mention the changes you have to do in OpneXava project configuration files to work it with MySQL.

If you are new to OpeanXava please go through the reference manual and have a basic knowledge first.

Ok, let’s get in to the business now.


1) MySQL database (ex. MySQL 5.0.24)
2) MySQL connector J (ex. mysql-connector-java-5.1.7-bin.jar)
3) OpenXava 3.1

Steps to follow

1) Create a new project (ex. Academy) according to the steps mentioned in the OpenXava reference guide.

2) Go to MySQL console and create a new database ex. academydb

3) Place MySQL connector jar into {OpenXavaBase}/tomcat/common/lib

4) Open the context.xml file in {OpenXavaBase}/tomcat/conf folder. Insert the following lines into the file.

name : name of the data source, use the default name OpeanXava gives. (Since I created the project as Academy, the default datasource name given is AcademyDS.
username: username of the MySQL database
password: password for the MySQL database
driverClassName: com.mysql.jdbc.Driver in this case
url: you have to point to the database you have creates. (ex. academydb)

5) Go to the project folder’s build.xml (Academy/build.xml) and change updateSchema target as follows. You have to change the value of the schema.path to point to the MySQL connector jar.

6) Go to persistence.xml (Academy/persistence/META-INF/persistence.xml)
Change the default persistence unit as follows

And change the junit persistence unit as follows

7) Go to hibernate.cfg.xml (Academy/persistence/hibernate.cfg.xml) and change the hibernate.dialect to org.hibernate.dialect.MySQLDialect as follows

That’s it, and now when you run updateSchema target, it will create the tables in MySQL and once you deploy the application, that will access the MySQL to retrieve and save data. (Assumed that you have written the relevant entity classes)


novicow said...

thank you very much. it was helpful.
i will read all that you will write about openxava. author, write else.

novicow said...

I spent some time trying to compare Domain Driven Java Frameworks
such as OpenXava, Naked Objects, Roma Framework.
I choose OpenXava to work with.

Java never die

Sanders said...

Thank, it save me a lot of time

Mirza Abazovic said...

I have error
org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.mySQLDialect
Some help please

Mirza Abazovic said...

It was a typo in persistence.xml and hibernate.cfg.xml

not mySQLDialect

but MySQLDialect

Thanks works perfect

Ahmed Hammad said...

Thank you, really helpful.

ashish said...

Thanks,Very helpful.

Faisal said...

Very nice. Thanks a lot.

Unknown said...
This comment has been removed by the author.
Unknown said...

it is not working with me, I followed the steps said, when I run the build.xml ant file it did not create table in the mySql.

I created the table manually and I run the project again I am getting

Sep 29, 2014 4:46:14 PM org.openxava.component.ComponentParser parseAnnotatedClass
SEVERE: Errors parsing warehouse: Seems that warehouse is not an EJB3 Entity nor transient model class.