• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obsolete Design Patterns for EJB3 & SCEA 5

 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Deepak Kanwar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Pilgrim
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mikalai Zaikin
Ranch Hand
Posts: 3367
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dario Laverde
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 3367
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Buddhika Pathiraja
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some body answer me ..
Can I assume J2EE 1.4 in the Part 2 Assignment [SCEA 5 Beeta] ???
 
David Michael Chen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read your assignment J2ee 5 is not requirement
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very interesting topic.

Thank you Cameron for start this .
 
Morten Franorge
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to consider injecting SFSB's unto your session scoped JSF Managed Beans instead.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic