Re: JPA2 Support inside Legacy and GWT Application

2011-09-19 Thread Juan Pablo Gardella
If you use Hibernate as JPA2 provider, you can see an Hibernate
Filterimplementation
in this
thread.
With this you don't need DTO objects.



2011/9/19 StrongSteve 

> Hi Jens,
>
> Thanks for the quick reply.
>
> I have the creation of DTOs and the JPA query language in mind. Thanks
> for pointing out.
> Our DB-Accesses are very straight forward, so no really complex
> queries.
>
> Just one more thing... Why is it important to have one EntityManager
> instance per request?
> What would the consequences be? If I am only allowed to have one
> EntityManager from the top till deep down in the business logic maybe
> it would be better to write a servlet filter and keep the
> EntityManager as a ThreadLocal variable for this request...
>
> Greetings
> Stefan
>
> On 19 Sep., 12:26, Jens  wrote:
> > Should work.. just make sure you only have one EntityManager instance per
> > request. I use a command pattern so I have one place where I can handle
> the
> > transaction (create transaction before command handler executes and
> commit
> > afterwards). But command pattern as well as DTO's leads to lots of
> classes
> > for a simple server request...don't know if I would choose it again
> > (command, command result, command handler, JPA entity, DTO class,
> possibly
> > DAO class). Also JPA's query language (JPQL) does not support everything
> > that native SQL supports so you have to keep that in mind (but sure you
> can
> > also execute native SQL queries with JPA if there is no other
> possibility).
> >
> > Currently I am looking into myBatis (http://www.mybatis.org/) for a new
> > projects. It uses native SQL and has some nice code generator support.
> Maybe
> > you should take a look at it, as you already have native SQL for a given
> > database.
> >
> > -- J.
>
> --
> 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-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

-- 
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: JPA2 Support inside Legacy and GWT Application

2011-09-19 Thread StrongSteve
Hi Jens,

Thanks for the quick reply.

I have the creation of DTOs and the JPA query language in mind. Thanks
for pointing out.
Our DB-Accesses are very straight forward, so no really complex
queries.

Just one more thing... Why is it important to have one EntityManager
instance per request?
What would the consequences be? If I am only allowed to have one
EntityManager from the top till deep down in the business logic maybe
it would be better to write a servlet filter and keep the
EntityManager as a ThreadLocal variable for this request...

Greetings
Stefan

On 19 Sep., 12:26, Jens  wrote:
> Should work.. just make sure you only have one EntityManager instance per
> request. I use a command pattern so I have one place where I can handle the
> transaction (create transaction before command handler executes and commit
> afterwards). But command pattern as well as DTO's leads to lots of classes
> for a simple server request...don't know if I would choose it again
> (command, command result, command handler, JPA entity, DTO class, possibly
> DAO class). Also JPA's query language (JPQL) does not support everything
> that native SQL supports so you have to keep that in mind (but sure you can
> also execute native SQL queries with JPA if there is no other possibility).
>
> Currently I am looking into myBatis (http://www.mybatis.org/) for a new
> projects. It uses native SQL and has some nice code generator support. Maybe
> you should take a look at it, as you already have native SQL for a given
> database.
>
> -- J.

-- 
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: JPA2 Support inside Legacy and GWT Application

2011-09-19 Thread Jens
Should work.. just make sure you only have one EntityManager instance per 
request. I use a command pattern so I have one place where I can handle the 
transaction (create transaction before command handler executes and commit 
afterwards). But command pattern as well as DTO's leads to lots of classes 
for a simple server request...don't know if I would choose it again 
(command, command result, command handler, JPA entity, DTO class, possibly 
DAO class). Also JPA's query language (JPQL) does not support everything 
that native SQL supports so you have to keep that in mind (but sure you can 
also execute native SQL queries with JPA if there is no other possibility).

Currently I am looking into myBatis (http://www.mybatis.org/) for a new 
projects. It uses native SQL and has some nice code generator support. Maybe 
you should take a look at it, as you already have native SQL for a given 
database.

-- J.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/6EMadWq1s3oJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



JPA2 Support inside Legacy and GWT Application

2011-09-19 Thread StrongSteve
Hello,

I am currently facing the task of adding a new database layer based on
JPA2 to both a standalone Java application as well as a GWT project
that is based on the business logic provided inside this standalone
Java application. (Basically GWT acts as the UI-layer by providing
service methods for accessing certain methods of the business
logic...)
The GWT application is running ontop of Tomcat 6 (so no EJBs, ... -
But EJBs would not work in the standalone application... so no need to
feel pitty ;)
Right now the database connectivity is solved by direct SQL commands.

The standalone application has to be runnable without the GWT project
as well. Especially the JPA2 connectivity.

So here is my approach so far, which I would like to discuss.

1.) Create DB-Entitiy objects for all needed DB-Tables.
2.) Create some kind of static class that holds the
EntityManagerFactory for our persistence context.
3.) As soon as any method (inside the business logic of the standalone
application or within a GWT service class) needs to create/update/read/
delete data from the database, use the EntityManagerFactory from the
static class to obtain a new entitymanager.
4.) Perform the transaction and close the entitymanager at the end of
the method.
5.) Objects transferred between the server and the client are simple
DTOs. No annotations or anything. The service methods will wrap the
objects obtained from the database into the corresponding DTOs. The
update process works the other way round.

This way both the standalone application as well as the GWT
application would work fine, am I right?
No problems with parallel sessions, ... or am I overseeing anything.
It is kind of the same approach Google Guice suggest by creating a new
Entity Manager for every HTTP Request with the help of a
ServletFilter. But honestly I can not see the need for dependency
injection in my scenario.

The only difference is, that my solution does not create an
EntityManager automatically with the help of a ServletFilter, but
manually through the EntityManagerFactory obtained from the Singleton
class.

Please share your comments, advices, hints on the proposed
approach. ;)

Thanks in Advance for your help!

Greetings
Stefan

-- 
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.