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!
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
22 comments:
Just a gentle nudge to get the rest of your series published. I am having a really hard time getting Hibernate annotations working in GWT!
Hi I'm going to publish the rest of the tutorial very soon as a couple of people have asked for it now!
Did the first section make sense?
The next parts also introduce Tapestry with the technologies.
It made sense. I'm not familiar with Tapestry so that should be interesting. I've gotten a simple Hibernate app together but I am having trouble with the reluctance of the GWT compiler to accept jdk 1.5 annotated classes (i.e. hibernate pojo in client code over RPC). I'm now looking at using hibernate4gwt.
Yeah you will always have that reluctance. The application in the tutorial will use Hibernate annotations but the persistent classes are simply on the 'server' side. You then need to make DTO objects for the client side. Again you'll wrestle with the language support within GWT as you can for instance just pass objects over they must be DTO objects which will be serializable.
I've posted a section of part two to the tutorial link given at the bottom of this page is still a work in progress though!
Can you let me know if part two is making sense so far? I'm uploading more today.
Hi,
as it seems, there are many ways to get Spring and GWiT up and running...
Choose you pill...
Hi there
Just looked have you compiled a similar tutorial also?
Not really. It is not a tutorial, just wiring up things slightly different.
Have you seen this here?
http://blog.digitalascent.com/2007/11/gwt-rpc-with-spring-2x_12.html
I hadn't seen it until looking at your blog. Checked it through your blog after reading your comment.
Hi i used your example and i am getting
[WARN] StandardWrapperValve[shell]: Servlet.service() for servlet shell threw exception
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName(Class.java:164)
Hi there,
Have not seen that error before?
A bad version number possibly means that you need to completely clean the project and rebuild?
Also check the Jars included and that some are not duplicated.
Failing that you can download the project here.
Will I be able to run the project with GWT 1.5?
Hi there,
Yeah you should be able to.
In GWT 1.5 they have made the RPC slightly easier.
The interface for the RemoteService in my example TeacherService should just have an annotation (before the class definition) of:
@RemoteServiceRelativePath("teachers")
and then when you call the RPC replace :
TeacherServiceAsync teacherService = (TeacherServiceAsync) GWT.create(TeacherService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) teacherService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "teachers";
endpoint.setServiceEntryPoint(moduleRelativeURL);
with:
TeacherServiceAsync teacherService = (TeacherServiceAsync) GWT.create(TeacherService.class);
teacherService.getPupils(teacherId, new AsyncCallback<List<PupilDTO>>()
{
public void onFailure(Throwable caught)
{
// TODO Auto-generated method stub
}
public void onSuccess(List<PupilDTO> result)
{
pupils = result;
notifyObservers();
}
You should also remove all the gwt.typeArgs annotations and have strongly typed sets.
Any further questions please ask. I might update the tutorial for GWT 1.5 as well seems like something that should be done
Hi
I have made a new post on the tutorial and GWT 1.5 migration
http://eggsylife.blogspot.com/2008/11/hibernate-spring-and-gwt-for-gwt-15.html
Thanks very much. I am going to test the project. Can I let you know how the testing went?
Actually, I need to test this with MySQL. I have problems with my PostGres installation, because I tried to uninstall a previous version and that did not go well, I think, because the new installation just won't proceed.
How hard would it be to get your project working with MySQL?
Thanks again.
Hi there,
Yeah keep us updated and please by all means ask questions here.
Using mySQL shouldn't be any different to using PostgreSQL you'll just have to change the usual Hibernate Setup parameters such as the DB driver
I could not find a link to download the Project file from here: http://www.filefactory.com/file/9771e7/n/TheProject_zip
Should I sign up there or something like that?
thanks
I tried to download again,and I got the following page that said:
"Sorry, there are currently no free download slots available on this server.
Please try again later, or you can upgrade to FileFactory Premium for instant access."
I created an account on FileFactory and was able to download using the option "Download with Basic..".
Post a Comment