Re: Can I put the business logic in Servlets and bypass EJB?
Tom Anderson wrote:
I think a sensible engineering decision would be to apply the You Aren't
Gonna Need It rule, and build your system with POJOs for now. However,
try to structure it so that a transition to EJBs later, if you decide to
make one, would be as painless as possible. That's pretty simple: define
your business objects with interfaces, and manipulate them exclusively
through those, and encapsulate creation of business objects (including
searching the database to make them) in a factory object (possibly using
the Facade pattern to hide a bunch of classes which do the creation work
behind a simple interface).
Then, if you want to go EJB, all you have to do is upgrade the
interfaces to EJB interfaces, fix up your client code to deal with
RemoteExceptions all over the place, and rewrite the factory object to
use the EJB finders. Oh, and then implement the actual EJBs. But at
least the changes to the servlet will be minimal.
Many would do the EJB's not as a replacement for the POJO's but
as a frontend for them to enable reuse of the business logic
in both high end (full Java EE with EJB's) and low end (just
Tomcat) solutions.
Huge caveat: i did a lot of work with EJBs, but quite a while ago -
specifically, before EJB 3, which i understand has changed things a lot.
Like, there are no entity beans any more, so all the above advice is
worthless. Eh. Maybe it still applies to session beans.
An EJB3 session bean should be POJO compatible.
Arne