GWT and RPC using hibernate

364 views
Skip to first unread message

MarkOD

unread,
Jun 20, 2006, 10:51:31 AM6/20/06
to Google Web Toolkit
Hi all,

I am currently trying to use GWT and hibernate.

I have tested my RPC example without any hibernate code and it all
works fine.

But when I call some hibernate code that I have already testing in a
servlet
ie:
...

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import net.sf.hibernate.cfg.Configuration;

public class MyServiceImpl extends RemoteServiceServlet implements
MyService
{

public String myMethod (String s)
{
try {

Configuration cfg = new Configuration(); //This is the line
that is causing the error
...

return "a test string";


I get the following error :


com.google.gwt.user.client.rpc.InvocationException: The call failed on
the server; see server log for details.

Can anyone point me to an example of hibernate or JDBC with GWT or in
the right direction.


Thanks


Mark

holgzn

unread,
Jun 20, 2006, 4:03:51 PM6/20/06
to Google Web Toolkit
Did you test cour GWT-code in hosted mode or inside a servlet
container ?

When running in hosted mode, you must ensure that all needed jars are
included in the running environment (in eclipse by setting up the
'Run...'-Environment, or by adding the jars to the launch-script).
The GWT-Development Shell should provide information about Exceptions.
Of course, you also need the hinernate.cfg.xml (if you use one) in your
classpath. For hosted mode, this can be achieved by putting it inside
the 'bin' directory.

When running in productive mode inside a servlet container, you have to
place all jars and the hibernate.cfg.xml into the usual directories
(WEB-INF/lib for jars and lib/classes for hibernate.cfg.xml).

Please let me now, if this could help you to locate the error.

There is one thing, i found useful with hibernate and GWT: You can use
the Hibernate-Objects on your client-side GWT code by addind their
source to your GWT project and replacing 'implements Serializable' by
'implements IsSerializable'.
For information on how to add non-gwt sources to your project, refer to
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/2a7d78d1599713c6/bb17c06ce9c34b5a

mP

unread,
Jun 20, 2006, 6:35:41 PM6/20/06
to Google Web Toolkit
Surely that would not work if hibernate was giving back proxies.

For testing purposes one should use mock objects and only introduce
hibernate into the question when integrating, when it becomes obvious
that hibernate msut be available to the server. One needs to then use
the value object - dto pattern to pass values between both tiers.

mP

wylp...@gmail.com

unread,
Jun 20, 2006, 11:40:11 PM6/20/06
to Google Web Toolkit
There is one cases is the oracle jdbc (这里有一个例,是oracle
jdbc的)http://www.blogjava.net/peacess/archive/2006/06/01/49447.html

MarkOD

unread,
Jun 21, 2006, 3:49:47 AM6/21/06
to Google Web Toolkit
Hi holgzn,

Thanks for the quick reply.

I have tried it both in hosted mode and running inside tomcat with the
same error.

The strange thing is that I am getting no error messages in the
GWT-Development Shell .

I'll let you know how I get on

Thanks

Mark

MarkOD

unread,
Jun 21, 2006, 3:56:26 AM6/21/06
to Google Web Toolkit
Thanks for the jdbc example.
That works great.

All I have to do now is to get it working using hibernate instead and I
will be a happy man.


Thanks

Mark

david....@gmail.com

unread,
Jun 21, 2006, 1:26:18 PM6/21/06
to Google Web Toolkit
I have GWT working with Hibernate objects RPCed to/from the client. I
have run into a few gotchas so far:

1) Hibernate puts java.sql.Timestamp instances into java.util.Date
persistent fields on retrieval from the database. These have to be
replaced with java.util.Date's before the instance can be sent to the
client app.

2) java.util.List fields end up as HibernatePersistentBag (or something
similar). These also have to be replaced with ArrayList instances
before the instance can be RPCed to the client.

3) I am using the EJB 3 persistence API but I cannot use the
annotations in my persistent classes as the GWT compiler is 1.4 only.
So I have to use an orm.xml file which is a pain.

4) The persistent classes cannot implement java.io.Serializable. This
mnight be a problem if they need to go to other sorts of clients (e.g.
Swing app) or whatever.

Cheers
David

MarkOD

unread,
Jun 21, 2006, 3:18:22 PM6/21/06
to Google Web Toolkit
Hi David ,

Thanks for the tips.

I'm going to stick with trying to get the hibernate \ GWT working for
the time being.

If time beings to run short I might start coding the service using JDBC
which I got to work.

Instead of java.io.Serializable I set the persistant class to implement
implements com.google.gwt.user.client.rpc.IsSerializable.

I think I must be doing something fundamentally wong because even the
simple line :

SessionFactory session = sessionFactory.getCurrentSession();

causes the com.google.gwt.user.client.rpc.InvocationException: The call


failed on the server; see server log for details.

I can't find any logs in the tomcat folder and I have tried getting the
StackTrace from the onFailure method but I have no found anything
useful from this so far.

I'll let you know how I get on.

Thanks again.

Mark

rbon...@sardiniapoint.it

unread,
Jun 22, 2006, 6:01:21 AM6/22/06
to Google Web Toolkit
Hi Mark
I use normaly GWT and Hibernate without problem with a JBOSS server.
I follow the istruction wrote by Bruce
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/338c4b765d7dfc39


package description

com.sp.schedacasa here I put SchedaCasa.gwt.xml
com.sp.schedacasa.server here I put SchedaCasaServiceImpl.java and
HibernateSessionFactory.java
com.sp.schedacasa.server.db.tabelle here I put hibernate.cfg.xml,
tabelname.hbm.xml and all my DAO files


com.sp.schedacasa.public generate by GWT compiler
com.sp.schedacasa.client the normal java class to implement widget
dataprovider async service ecc...

I'm sorry for my bad english hope that my post will help you.
For any problem contact me

Regards

Rinaldo

david....@gmail.com

unread,
Jun 22, 2006, 7:02:57 AM6/22/06
to Google Web Toolkit
Hi Mark

Try wrapping your server side code in a try { .. } catch (Throwable t)
{ t.printStackTrace(System.out); }.

You might be getting a NoSuchMethodError due to a missing jar or
something like that.

Cheers
David

MarkOD

unread,
Jun 22, 2006, 10:59:19 AM6/22/06
to Google Web Toolkit
Hi a happy man now. Got my hibernate code working.

A big thanks for all your help. I'll be able to use this in my project
now.

Thanks for the tip david. It was down to a couple of missing jars.

Thanks again.

Mark

ian

unread,
Jul 19, 2006, 12:56:12 PM7/19/06
to Google Web Toolkit
Hi Mark,

you cannot use IsSerializable "instead of" Serializable for the
Hibernate classes. As far as Hibernate is concerned, your persistent
classes must implement Serializable or a sub-interface of Serializable.
GWT's IsSerializable is a totally different Interface.

Reply all
Reply to author
Forward
0 new messages