• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does stateful or stateless session bean make sense ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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".
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic