views:

91

answers:

2

What would a stateless session bean provide over just a regular class that has the same methods? It seems that a stateful session bean can be distributed out of the box and the container will make sure that the state looks the same to clients anywhere. With a stateless session bean what is provided that you would not get with a normal class?

Is it just that your EJB tier can fail over if you have a distributed environment? It seems to me that you can get a local or remote instance of a stateless session bean, if I only use one server for my application and thus never use the remote interface is there any benefit?

+3  A: 

EJBs give you declarative security, transactions and remoting. When you call one of the EJB's methods, you actually pass through a stack of interceptors that provide the above layers of functionality.

A Plain Old Java Object wouldn't do any of that. Of course, if you don't need any of that, then EJBs are not necessary.

skaffman
+1  A: 

A stateless session bean provides the application container with knowledge about the intent of the services it provides. As it is stateless, the application container can decide at any moment in time to destroy the bean and recreate it the next time it is needed.

Without these semantics, the application container cannot optimize your application for speed/memory/whatever. So, although stateless session beans mostly resemble POJOs, they provide some additional "hints" for the application server.

If you would look at how stateless session beans should be implemented using the EJB3 specification, you would see much resemblance between it and a normal POJO (aside the additional annotations).

jawi