Archive

Archive for October, 2007

Hibernate, Spring, Google Web Toolkit – Part One

October 4th, 2007 admin 2 comments

Well this tutorial aims at helping people integrate the 3 technologies of Spring, Hibernate 3with Annotations and Google Web Toolkit. Definately easier said than done. This tutorial is made using the Eclipse IDE. This assumes that you are using Postgresql as your database.

Firstly a we need to get all the required stuff!

The Spring Framework

Hibernate 3 and Annotations

Google Web Toolkit

With Spring please make sure you download the -with dependencies distribution. Then read through the readme text file for the dependencies as to what you need to add to your classpath. Also the same for Hibernate and Hibernate Annotations.

Right firstly we need to make a new Google Web Toolkit project for Eclipse. This is pretty basic the commands were:

projectCreator -eclipse TheProject

applicationCreator -eclipse TheProject com.company.client.MyApplication

You can then go to Eclipse and File > Import the Project into the existing workspace.

If you take a look at the files in Eclipse you will see it has made the package com.company.client and the class MyApplication. Under the structure as well you’ll have a public folder and within that a HTML file. Right from here I like to restructure stuff.

Firstly I made my project a true web project with WEB-INF and the lark. So in my Eclipse project I have:

WEB-INF/classes
WEB-INF/src
WEB-INF/lib
WEB-INF/test

Important! Make sure you move the source code from the src folder into the WEB-INF/src folder and you can now delete the src folder. Now all the libraries required by Hibernate, Spring and Google need to be added to the lib folder.

On Eclipse now we need to configure the build path details. Right click your project and choose Properties to go into the project properties. Choose Java Build Path from the options.

Click the Source option and remove the current src folder then click add source and add the WEB-INF/src folder, then do the same and add the WEB-INF/test folder.

At the bottom for the output file change this to WEB-INF/classes and when it asks you to remove the current click to confirm.

Click the Libraries folder and click ‘Add jars’ then add all the jars in the lib folder to your classpath. Phew!! Nothing much really achieved so far!

The libraries I used can be seen on this screen shot from Eclipse.

Coming soon will be the creation of a single database with a single table and fully hibernate annotated.

Part Two can be found here