HiberObjects

Download

Order

Forum

Vote for this plugin

Creating an admin application for phbBB using GWT and JPA

This tutorial demonstrate how to use HiberObjects Import DB Pro to build an AJAX application for an existing database.

We will use HiberObjects to import a MySQL database for the well known forum phpBB3, and generate Java Persistence API (JPA) classes that map to that database.

The front end will be implemented with Google Web Toolkit (GWT).

The GWT and JPA classes will be connected with data transfer objects that are also generated by HiberObjects.

Install phpBB

The first step is to install phpBB3 locally, so I have something to test against. Apache is already installed on my Mac, so I just need to enable web sharing and PHP. I follow the instructions at Apache Web-Serving with Mac OS X to install PHP.

I download phpBB3 from http://www.phpbb.com and unzip it into my web pages directory. I open a web browser at http://localhost/~lars/phpBB3, the phpBB3 introduction page appears and I follow its instructions for installation.

Create an Eclipse Project

Before I import the database into HiberObjects, I need to create an Eclipse project for GWT:

cd <workspace> mkdir phpbb cd phpbb projectCreator -eclipse phpbb applicationCreator -eclipse phpbb com.objectgen.phpbb.client.AdminApp

(Read more about GWT here.)

Import this project into Eclipse: File -> Import, General, Existing Projects into Workspace, Next, Select root directory: <workspace>, Browse, Projects: select phpbb, Finish.

Create a source folder "conf" in the project.

The next step is to turn this project into a HiberObjects project: Select Project Properties, HiberObjects and enter the following options:

On the Persistence page:

Push Ok.

Import the Database

Create a package com.objectgen.phpbb.model package in the HiberObjects icon. Right-click on the package and select Import from database. Select the mysql driver, enter correct URL, user and password, and push Next.

What's that? Let's check importjdbc.log:

com.objectgen.jdbc.JDBCDriverNotFoundException: Could not load JDBC driver: com.mysql.jdbc.Driver

Of course, I need to add mysql driver to the project class path. I do this and try Import from database again.

This time it goes better, and a wizard appears:

So what does all this mean? The left side obviously shows the imported database tables and columns. To the right is detailed information about a Groovy script that builds classes and variables to map to the database.

The purpose of this wizard is to make it easy to edit and test this script, for instance to:

If you select an element in the left Table/Column tree, you will see that the Methods panel change. This panel shows the Groovy methods that are called for the selected table or column. The Method Code panel shows the actual code for that method, and the Method Result panel shows what the method returns.

The Total Result panel at the bottom shows the class or member that will be created for the selected table or column. This is the result of all the other methods combined.

Currently, Total Result shows some warnings. We will deal with this later.

Limitations

Some tables are red. If you select those tables, you will see the following error in the Total Result: Cannot import table; no primary key

This shows the limitation of importing an existing database; Some tables may not be possible to map to objects. These tables will have to be handled with queries, and some database s

Other limitations are:

Next: Configuring the Import