I'm using GWT and Hibernate. After reading the various posts about the
problems (and the fact that its a bad design idea) to pass Hibernate
objects back to the client, I've attempted to come up with as clean a
design as possible.
My first package contains my base classes, which implement getters and
setters as well as a few convenience methods.
My second package is for use with Hibernate. The classes are direct
subclasses from the first package and implement Serializable (My
classes access legacy tables and have composite-ids).
My third package is for use with GWT. The classes are direct subclasses
from the first package and implement IsSerializable.
The idea is that doing so, my base classes will not be dependent on any
persistence or presentation implementations. My servlet will use
BeanUtilsBean to convert from Hibernate instances to GWT instances.
Ex:
package 1:
package com.mycompany.myproject.meta;
public class Person {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
package 2: (for Hibernate)
package com.mycompany.myproject.hibernate.meta;
public class Person extends com.mycompany.myproject.meta.Person
implements Serializable {}
package 3: (for GWT)
package com.mycompany.myproject.client.meta;
public class Person extends com.mycompany.myproject.meta.Person
implements IsSerializable {}
I'm still trying out the GWT layer in Hosted mode for now and my
problem is as follows:
My service implementation servlet creates a GWT instance of a class
(from package 3) and returns it. However, when the client receives the
object, all the properties are null. I have tested this with a simple
class containing 2 string properties.
When I copy and paste the contents of the class from package 1 to
package 3, instead of subclassing, it works. The GWT compiler does not
complain about missing sources or whatever and no Exceptions are being
thrown.
Is there a way around this or do we have to replicate the full
implementation of the classes we wish to pass through RPC calls?
Also, any comments about this approach to the design are welcome.
Cheers,
Ian
You might look at a JavaBean-to-JavaBean copy utility like Jakarta
Common's bean utils to reduce the pain of data copying.
Any ideas regarding the problem:
" My service implementation servlet creates a GWT instance of a class
(from package 3) and returns it. However, when the client receives the
object, all the properties are null."
Cheers,
Ian
1) Unjar gwt-user.jar
2) Add a new file: com/google/gwt/emul/java/ui/Serializable.java:
package java.io;
public interface Serializable { }
3) jar the files back up
4) replace the original gwt-user.jar with the new.
Now have your classes implement *both* IsSerializable
and Serializable.
You will be able to pass them via gwt RPC, and also processes
them via normal java serialization on the server side.
This is fully tested (by me), and is working fine.
Google guys: Please consider adding Serializable.java
to the next release of gwt-user.jar! :)
I read the way you told to handle Serialization
Look at following scenario
1. I have a class named View implements IsSerialzable
its used in my client classes let say in my widgets
2. In my service servlet i call a stateless ejb to get this object
(View) from persistence store.
3. But my View is not Serializable
4. Wht i do in my ejb is tht i get the view object using hibernate and
send it to service servlet
5. When I get it on client its null.
The way you told in which i have to import
com.google.gwt.emul.java.io.Serialzable
Suppose Idid it and now my View also implemnts this interface
So when my object is being created on server sdie (i.e EJB) it will
create it perfectly as it does now.
But how it will serialize it while returning it to my service servlet.
as The EJB dosn't know how
com.google.gwt.emul.java.io.Serialzable serializes the things so May be
JVM will not think it as serialzable.
My questiion is just that how my EJB will take it as
java.io.Serializable implementation.
Can you please tell me wht you have done in your case........
Plz reply soon