Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes DAO patterns future with JPA? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "DAO patterns future with JPA?" Watch "DAO patterns future with JPA?" New topic
Author

DAO patterns future with JPA?

Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
I guess this question would have been perfect when Michael Keith was here, but I didn't think of it then. I bet there are others here that are qualified to answer this as well, so here goes:

* With the introduction of JPA, what is the future of the DAO-pattern?
* Do we need it?
* Will all DAOs be EJBs with local interface?
* I ask this because:
EntityManager needs to be injected into a EJB
EntityManager isn't thread safe

Last, will we see a new J2EE pattern catalog from sun, now that the EJB spec has been so dramaticly changed...?


SCJP 1.4, SCBCD 1.3, SCBCD 5.0, SCEA J2EE, SCEA 5.0
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Hi Morten,

Yes, good question. Fortunately, I came back for a visit just when you asked it :-)

* With the introduction of JPA, what is the future of the DAO-pattern?
Because entities can now leave the server, DAOs have become unecessary. However, some people still like them for other reasons, whether it be encapsulation of some other aspect or just for the purposes of layering their persistence API access (as Spring does).
* Do we need it?
I personally do not see them being very useful anymore and am very happy not to have an extra mirrored class hierarchy.
* Will all DAOs be EJBs with local interface?
No, they can be POJOs, or they can be whatever anyone wants them to be.
* I ask this because:
EntityManager needs to be injected into a EJB
EntityManager isn't thread safe
EntityManagers don't *need* to be injected. They can be obtained from JNDI, or from an EntityManagerFactory that was obtained either by injection of by a lookup. I am not sure why you are worried about the thread safety of the EM. This is not an issue if you are using a session bean since every session bean will obtain a new instance of the EM so no concurrency issues will arise.
Last, will we see a new J2EE pattern catalog from sun, now that the EJB spec has been so dramaticly changed...?
Yes, the Java EE 5 patterns are being rewritten.

-Mike


-Mike
Pro JPA 2: Mastering the Java Persistence API
Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
Originally posted by Mike Keith:


EntityManagers don't *need* to be injected. They can be obtained from JNDI, or from an EntityManagerFactory that was obtained either by injection of by a lookup. I am not sure why you are worried about the thread safety of the EM. This is not an issue if you are using a session bean since every session bean will obtain a new instance of the EM so no concurrency issues will arise.

-Mike


I guess there won't be a problem. Looking up the EM from the DAO IMO won't be good solution, it conflicts with the IoC that I strive to use for my designs.

Is the following code safe if it's in a SFSB or a SLSB


Nice to hear the patterns are re-written, I guess there are a lot of new issues that needs a common solution now that JPA and POJO-style EJBs are introduced.

Do you happen to know anything about a new EJB certification as well?
I guess the Sun guys might wait until the JPA is taken out of the EJB spec (or they can take it out of the certification now).
A JPA certification would be a good adition to the sun certification suite..
[ September 05, 2006: Message edited by: Morten Fra Norge ]
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Yes, that code should work fine as long as the DAOs don't outlast the session bean that creates them (and it doesn't look like they will).

I don't know anything about the certification process or schedule. The blueprints are already in the process of being written, though, they are just not done yet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DAO patterns future with JPA?