wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Does stateful or stateless session bean make sense ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Does stateful or stateless session bean make sense ?" Watch "Does stateful or stateless session bean make sense ?" New topic
Author

Does stateful or stateless session bean make sense ?

Oliver Hamukodo
Greenhorn

Joined: Oct 17, 2004
Posts: 5
I have an existing web application that was written in servlet/jsp. I want to inject EJB tech to rewrite it. The application is a database query and display type. No transaction or database update involved. Here are my questions ---

1. Since there is no transaction or database update involved, should I think using EJB is a overkilling ?

2. Somehow I feel I can use session bean for the following purposes: I have lot of calculation and logic stuff, this can be done by stateless session bean; I have some Action classes that basically do the database query and return some data structure for front end display, I can use session bean to replace these Action classes. Are these 2 ideas correct ?

3. Assuming I can use session beans to replace the Action classes, I am not sure if stateful or stateless bean is better. The application consists of several pages. user picks some criteria on 1st page and the 2nd page is displayed based on 1st page's search results, and then user picks search criteria on 2nd page, so the 3rd page is displayed based on previous page's choices... So I have a Action1.java, Action2.java, etc corresponding to Page1, Page2's search work. It seems I can convert them into stateless session beans because everytime I just do a search by giving some search criteria, that's it, I get the search results and display it. Does this make sense ?
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
If you're not using anything provided by the EJB container, then you probably shouldn't be going to all the trouble of rewriting it. If you want to do some stuff to make your application less coupled (more MVC), then by all means do that. But don't feel like you need to use EJB as your model over POJOs if the circumstances don't fit.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
Originally posted by Nathaniel Stoddard:
If you're not using anything provided by the EJB container, then you probably shouldn't be going to all the trouble of rewriting it. If you want to do some stuff to make your application less coupled (more MVC), then by all means do that. But don't feel like you need to use EJB as your model over POJOs if the circumstances don't fit.


I think it is hard to define "using server resource". Server has lot of resources available like connecction pooling, etc. Talking about the beans, even you don't use entity beans or transaction, you can use stateless bean that is highly scalable, in this way you are still using some server resources but not all of course.

So I think in this case you can try using session beans (I will leave the choice of stateful/stateless to you) to rewrite. Of course, you don't "have to" rewrite your servlet/jsp, but you can apply some EJB if you "want to".
Pradeep Ram
Greenhorn

Joined: Sep 29, 2004
Posts: 18
I may not profess to grasp the intricate concepts of your application, but from what you have stated it appears that EJB might not be a preferred solution. IMHO, POJOs are better at this point.

I understand that you have a need for storing information from the session (i.e page 1- page 2). If you really need sessions , you can use HTTPSession, you would not need Stateful Session beans. From your statement, it appears that the information can be captured in the request object itself and subsequently passed to next page, by means of a hidden variable or any other mechanism.

There are a couple of things that you can leverage by using an Enterprise Server, like Connection Pools, Object Pools, Authentication/security etc .. If you can take each of the features of the container and decide whether you need it or nor, It will help you make a good decision.

My recommendation would be to use the appropriate design pattern to decouple your application so that you can replace certain aspects of it with a different technology at a later date (look into Business Delegate or Command pattern etc ..).
--pradeeP
Oliver Hamukodo
Greenhorn

Joined: Oct 17, 2004
Posts: 5
Originally posted by Pradeep Ram:
I may not profess to grasp the intricate concepts of your application, but from what you have stated it appears that EJB might not be a preferred solution. IMHO, POJOs are better at this point.

I understand that you have a need for storing information from the session (i.e page 1- page 2). If you really need sessions , you can use HTTPSession, you would not need Stateful Session beans. From your statement, it appears that the information can be captured in the request object itself and subsequently passed to next page, by means of a hidden variable or any other mechanism.

There are a couple of things that you can leverage by using an Enterprise Server, like Connection Pools, Object Pools, Authentication/security etc .. If you can take each of the features of the container and decide whether you need it or nor, It will help you make a good decision.

My recommendation would be to use the appropriate design pattern to decouple your application so that you can replace certain aspects of it with a different technology at a later date (look into Business Delegate or Command pattern etc ..).
--pradeeP


I think you basically get what my application is about. Now I want some more specific information as I am new to EJB stuff --- If my application involves transaction, certainly EJB will be a good choice, I know that.
Can you give me some concrete examples that EJB is a suitable choice when transaction is NOT involved ? I can tell one immediately --- shopping cart application. Every book uses shopping cart as example for stateful session bean. I want to know some more concrete examples. Please name and describe couple if you can.

Finally I want to know --- Why isn't it a good idea to replace those Action classes (like struts action classes) by session beans ?

thanks,
oliver
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does stateful or stateless session bean make sense ?