File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Obsolete Design Patterns for EJB3 & SCEA 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Obsolete Design Patterns for EJB3 & SCEA 5" Watch "Obsolete Design Patterns for EJB3 & SCEA 5" New topic
Author

Obsolete Design Patterns for EJB3 & SCEA 5

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Anderson Fonseca made an interesting and important point in a previous JavaRanch thread, about how certain design patterns don't make much sense in JEE 5. I'd never really thought about it, actually. I mean, part of any assignment is to not only design what you think is right, but to pepper in those things that you think the people marking the exams would want.

So, if you pick up a copy of Cade's SCEA J2EE Study Guide, or even the J2EE Design Patterns Book, which is suggested reading material for this exam, you'll probably want to pepper in things like a data transfer object pattern, or even a service locator. I mean, what J2EE application doesn't need to locate an important service. And a service locator looks soooo good right after a servlet or some other front controller handles a request.

But wait! EJB3 entity beans are really just annotated POJOs right? So, if the EJB3 entity bean becomes detached from the entity manager, why do you need a transfer object? Why not just push the detatched POJO back to the client, especially if you're on the same JVM? So, does the use of a DTO in your design demonstrate a fundamental lack of understanding of how EJB3 works? Here's an interesting thread from Sun about EJB3 and Design Patterns. This article even questions the need for a DAO design pattern, although I do think that's a little over-anxious. I appreciate the application layering aspect of the DAO pattern.

And with EJB3 resource annotations, and simplified lookups, do we even need a service locator anymore? Would the inclusion of one in your design demonstrate a lack of understanding of JEE 5? Here's an interesting article on the so-called death of the service locator?

How EJB3 Kills Off The Need For The Service Locator

So, what else gets thrown to the way side? Which design patterns are now 'deprecated' by the advances of EJB3, and even moreso, which patterns are more important than ever? Session Facade? Abstract Factory? Front Controller?

Any input, links to documentation, or interesting insight would be appreciated. This will help all of us SCEA 5 hopefuls avoid the pitfalls of thinking like a haggard old J2EE architect.

Here's a good link, pulled from the previous JavaRanch thread, discussing how applicable the J2EE Design Patterns Book is today: Eclectic Programmer - J2EE Design Patterns in a World of Lightweight Java Objects.

-Cameron McKenzie

By the way, I'm working hard on an SCEA5 book for JEE5 certification, but who knows when it will be out. I'm working on it though!
[ September 08, 2008: Message edited by: Cameron Wallace McKenzie ]
Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
What about lookups of stateful session beans? Don't they need to be looked up still? You can't inject them into a servlet...you have to look them up in jndi once, then keep them in the httpsession etc?


SCJP 1.4, SCBCD 1.3, SCBCD 5.0, SCEA J2EE, SCEA 5.0
Deepak Kanwar
Greenhorn

Joined: Jun 17, 2006
Posts: 14
You can inject EJBs or any resource into servlets - you can inject EJB 3 stateless and stateful session beans, EJB 2.1 Home, DataSource, ORB, UserTransaction, javamail session, JMS ConnectionFactory, JMS Queue, JMS Topic, etc. etc.

You can not inject resources into classes which are "not managed" by container like normal javabeans but servlets are container managed so you can.


------------------------------<br />IBM RUP Specialist,IBM SOA solution developer,IBM XML solution developer<br />SCEA ,SCBCD , SCWCD, SCJD, SCBCD 5, SCEA 5(In progress)<br />------------------------------
Peter Pilgrim
Greenhorn

Joined: Nov 05, 2002
Posts: 21
Originally posted by Deepak Kanwar:
You can inject EJBs or any resource into servlets - you can inject EJB 3 stateless and stateful session beans, EJB 2.1 Home, DataSource, ORB, UserTransaction, javamail session, JMS ConnectionFactory, JMS Queue, JMS Topic, etc. etc.

You can not inject resources into classes which are "not managed" by container like normal javabeans but servlets are container managed so you can.


You should probably look at on-line resources on JPA and annotations.

One thing I do not understand from a UML point of view is how does one represent annotations?

It is not a generalisation, but a kind of mark-up. In C# they call their concept of annotations, actually, attributes. I think this is a big clue, but I do not know the correct UML form for sure.
[ November 28, 2007: Message edited by: Peter Pilgrim ]

--<br />[bold]Peter Pilgrim[/bold]<br />Java EE Developer, Designer and Architect<br/>Oracle Java Champion<br /><a href="http://jroller.com/peter_pilgrim" target="_blank" rel="nofollow">http://jroller.com/peter_pilgrim</a>
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
Originally posted by Deepak Kanwar:
You can inject EJBs [...] into servlets - you can inject EJB 3 [...] and stateful session beans


That's invalid statement. :roll:


regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Dario Laverde
Greenhorn

Joined: Feb 27, 2006
Posts: 16
@Mikalai,

Oh yes you can inject EJBs into servlets, see OpenEJB or JBoss Embedded and pretty soon the embedded Glassfish EJB containers. You can argue that it's non-standard, but it's not against the EJB 3 specs per se.

Depending on the particular case your are designing an architecture for, I'd say it's valid to indicate DI of your EJBs into servlet components in your component diagrams.

-Dario
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
Originally posted by Dario Laverde:
@Mikalai,

Oh yes you can inject EJBs into servlets, see OpenEJB or JBoss Embedded and pretty soon the embedded Glassfish EJB containers. You can argue that it's non-standard, but it's not against the EJB 3 specs per se.



-Dario


Dario !

I am Ok with injecting EJBs in Servlets.

The key point was doubt in injecting (see the part I quoted above) stateful session beans in Servlets.

Sorry for confusing.

Best regards,
MZ
James Jurach
Ranch Hand

Joined: Jan 18, 2007
Posts: 35
Originally posted by Peter Pilgrim:
One thing I do not understand from a UML point of view is how does one represent annotations?
[ November 28, 2007: Message edited by: Peter Pilgrim ]


I can't remember where I read it recently, but it is intuitive enough to try to demonstrate this now myself: there is a strong affinity between "annotations" and "stereotypes". A class, interface or any UML element can be ornamented with one or more stereotypes just as a class, interface, field, or method can be ornamented with one or more annotations. Annotations convey some special type of behavior the way stereotypes do.

I concede this similarity between stereotypes and annotations breaks down when we start talking about named arguments. I suppose those would attributes of the stereotypes which I don't believe exist in the UML. Maybe there is no mapping for named arguments of annotations except to be listed within a linked comment element.


James Jurach
Developer
SC{JP5,JD5,WCD,BCD5,EA5}
Buddhika Pathiraja
Greenhorn

Joined: Aug 29, 2003
Posts: 4
In SCEA BEETA PART 2 assignment can we assume we are using J2ee 1.4 ?
in J2EE 1.4 all the design patterns are relevant...
Buddhika Pathiraja
Greenhorn

Joined: Aug 29, 2003
Posts: 4
Can some body answer me ..
Can I assume J2EE 1.4 in the Part 2 Assignment [SCEA 5 Beeta] ???
David Michael Chen
Greenhorn

Joined: Nov 30, 2007
Posts: 10
Read your assignment J2ee 5 is not requirement


David Chen<br />Java is my skin
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Buddhika Pathiraja:
Can some body answer me ..
Can I assume J2EE 1.4 in the Part 2 Assignment [SCEA 5 Beeta] ???


You can use J2EE 1.4.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
This is a very interesting topic.

Thank you Cameron for start this .
Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
My question wasn't whether you can inject EJBs into servlets or not. It was whether you should. Of course SLSB makes sense, however as Servlets are singletons SFSB would be shared across all web clients. I doubt any one who would use SFSB would like to do that, as state is very much tied to one specific client!
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
You might want to consider injecting SFSB's unto your session scoped JSF Managed Beans instead.


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Morten Franorge:
My question wasn't whether you can inject EJBs into servlets or not. It was whether you should. Of course SLSB makes sense, however as Servlets are singletons SFSB would be shared across all web clients.

How that happens? I cannot follow.
Jose Huizar
Greenhorn

Joined: Nov 21, 2007
Posts: 9
I think design patterns are still useful in J2EE 5, it's a good idea to hide the details of looking up an object maybe you'd like to switch the look up mechanism for your app from ejb dependency injection to one based in spring.

Also, keeping DTOs in your design may help decouple your domain model from the way they're presented in the UI tier.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Jose Huizar:
I think design patterns are still useful in J2EE 5, it's a good idea to hide the details of looking up an object maybe you'd like to switch the look up mechanism for your app from ejb dependency injection to one based in spring.

Also, keeping DTOs in your design may help decouple your domain model from the way they're presented in the UI tier.

I think you mean composite Transfer Object, right?
Selina Tan
Ranch Hand

Joined: Apr 29, 2008
Posts: 30
hi,
just found this thread while trying to nail the scope for SCEA 5 part 2 and I find it very informative


btw does anyone know when is sun going to update the core j2ee patterns blueprints.
Farbod H Foomany
Ranch Hand

Joined: Feb 29, 2008
Posts: 63
Hi,
Thank you for bringing this up. And I am still waiting for Cameron's book, putting off taking the exam!
Tomas Augusto Muller
Greenhorn

Joined: Oct 03, 2008
Posts: 3
And which patterns is recomended to use, when integrating a client application with EJB3 running on server?

Example:
- an application built on top of Eclipse Rich Client Plataform, needs to access business methods available in EJB3 running on a server.

Regards,


Tomas Augusto Muller
http://tomasmuller.com.br/
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

And perhaps it's worth updating this thread by pointing to some discussions on whether the DAO pattern is relevant when EJB3 provides its own Persistence Manager:

Some Good Discussion on DAO/EJB3 Pattern Midway Through the Thread

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Obsolete Design Patterns for EJB3 & SCEA 5