Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » JPA EntityManager (Suggestions for managing EntityManagers?)
icon5.gif  JPA EntityManager [message #521956] Fri, 19 March 2010 08:49 Go to previous message
Eclipse UserFriend
Hello,

this is not really RAP specific, but since RAP is a little different from traditional web applications (page requests) I decided to ask it anyway.
I think the question has been asked before, but I still couldn't find a good solution.

Does anybody have suggestions on how to manage the JPA2 EntityManagers in an RAP application?

There are some 'standard' patterns for "application managed" EntityManagers, but none of them seems right to me.

1. method scoped
Create and close the EntityManager in the method that uses the EntityManager...but...what about lazy loading of relations..updating entity properties....and in general performance?

2. unit of work
Create the entity manager when you are about to start some complex operation, close it, after the operation is finished.
For complex business operations this really makes sense. But for simple CRUD operations 'unit of work' is basically the same as method scoped, isn't it?

2. request scoped
In a traditional web application that would be the preferred way for me. Create the EntityManager at the page request (if needed) and close it after the page has been processed.

3. view scoped
One EntityManager for every view of the application. I don't like this one, because I don't want the data access layer to know anything about views and nor do i want a view to know anything about entity managers.

4. application scoped
That would be creating an EntityManager when the application starts, and closing it, when the apllication ends. This one cannot be used in RAP applications, because multiple users would share the same EntityManager and try to access it at the same time.

5. session scoped
Create an EntityManager when a user starts a session and assign it to that session. Close the EntityManager, when the session ends (ISessionStore.addSessionStoreListener).
This is also known as Anti-Pattern (I think mainly because of scalability).
But still, this seems the best way to to it in RAP. There won't be any concurrency issues and I can cleanly close the EntityManager in 'beforeDestroy' by registering a SessionStoreListener. Access to the EntityManager would still needed to by synchronized (fast clicking users)

So really: what's wrong with session scoped EntityManagers?
Or what other options do I have? How do you manage your EntityManagers in RAP applications?

To be clear: I am not talking about container managed EntityManagers, I am talking about application managed EntityManagers.

Thanks for your help.

Markus

[Updated on: Sat, 20 March 2010 05:51] by Moderator

 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:Request.js - eval not in global scope for IE
Next Topic:[ANN] RAP 1.3 M6 is available
Goto Forum:
  


Current Time: Thu Jul 17 00:46:03 EDT 2025

Powered by FUDForum. Page generated in 0.04011 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top