Using a JPA Entity in the client

77 views
Skip to first unread message

Cristiano

unread,
Jun 30, 2011, 2:45:42 PM6/30/11
to Google Web Toolkit, sergio...@gmail.com
Hello All,

While searching for instructions and best practices for using GWT and
JPA, I see everywhere guides suggesting to create 2 different bean
classes, a JPA Entity for handling on the server-side the persistence
on the database, and a DTO for exchange between the servlet and the
browser...
These guides suggest that GwtRpcService interface uses the DTO bean in
the method signature, and in the GwtRpcService implementation, the DTO
has to be transformed to the Entity bean so to persist it on the DB.


I have instead developed a test application where I have only one
single bean, placed in the client folder and annotated with JPA's
@Entity, and I exchange it within my RPC service interface.
This way it is elegant as I do not have to handle to different classes
and convert them, and from my test, it is simple and it seems to _be
working fine_.

Anyone can give me good reasons why I shouldn't follow this
approach?

To be noted that someone says that to follow this approach,
RequestFactory should be used instead of RPC service... why?


Here the significant information about my test project:

the GWT module is net.cristcost.test.jpa.TestJpa.gwt.xml,
the GWT client package (<source path="client" />) is
net.cristcost.test.jpa.client,
the bean is net.cristcost.test.jpa.client.MyBean;
the RPC Service interface is
net.cristcost.test.jpa.client.MyBeanManagerService;
the RPC Service implementation is
net.cristcost.test.jpa.server.MyBeanManagerServerImpl;

the RPC service has these two methods:
public void addBean(MyBean bean);
public List<MyBean> getBeans();

And here the relevant lines of the bean:
--------------------------------------------
package net.cristcost.test.jpa.client;

// imports...

@Entity
@SuppressWarnings("serial")
@Table(name="my_beans", schema="jpa_test")
public class MyBean implements Serializable {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;

@Column(name="object")
private String object;

@Column(name="subject")
private String subject;

// ... class continues with getter and setters ...
}
--------------------------------------------

Thanks,
Cristiano

Juan Pablo Gardella

unread,
Jun 30, 2011, 2:49:15 PM6/30/11
to google-we...@googlegroups.com
I use this approach and I preferr to RF, is more simple. But you need something in the middle to pass jpa classes with proxies (if you use Hibernate).

I use the approach mentioned in this thread. No DTO, no Gilead. I will share the code soon.

2011/6/30 Cristiano <cristiano....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Cristiano

unread,
Jun 30, 2011, 2:56:10 PM6/30/11
to Google Web Toolkit
Hello Juan,
thank you, did you find any bad side effect?

Ops! I forgot to say I use EclipseLink and GWT 2.3.0.

Cristiano




On 30 Giu, 20:49, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> I use this approach and I preferr to RF, is more simple. But you need
> something in the middle to pass jpa classes with proxies (if you use
> Hibernate).
>
> I use the approach mentioned in this
> thread<http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse...>.
> No DTO, no Gilead. I will share the code soon.
>
> 2011/6/30 Cristiano <cristiano.costant...@gmail.com>

Jeff Larsen

unread,
Jun 30, 2011, 3:07:52 PM6/30/11
to google-we...@googlegroups.com
If you return a collection in your pojo (List, Map, Set etc) those will not serialize correctly. 

Juan Pablo Gardella

unread,
Jun 30, 2011, 3:10:55 PM6/30/11
to google-we...@googlegroups.com
This side effect will fix with a filter. But I don't know how works Eclipse Link.

2011/6/30 Jeff Larsen <lars...@gmail.com>
If you return a collection in your pojo (List, Map, Set etc) those will not serialize correctly. 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
Reply all
Reply to author
Forward
0 new messages