• Post Reply Bookmark Topic Watch Topic
  • New Topic

Urgent: Howz stateful diff frm entity beans  RSS feed

 
amit shukla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
please help me i'm a bit confused .. if a stateful session bean is using database to store data same as entity beans do how persistence comes into picture as both are having permanent persistence in the form of database.. so it doesn't matter whether you shutdown or restart the server as your data is still safe.. so what actually is the difference.. plz guide me..
thanx
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful session beans do not store in a DB (at least not in the way that entity beans do). A stateful session bean is not mapped to a database. The only time a stateful session bean is written to persistent storage is when it is passivated.
A stateful session bean represents a business logic bean that will be assigned to one and only one client. An entity bean represents business data that is stored in a database.
The difference is clearer when talking about the difference between stateless and stateful session beans. Stateless session beans are almost like static classes. They should not store any data unique to a client because the client can not guarantee they will get the same bean on the next request. In fact, the EJB Server will whip up a batch of stateless session beans and hand them out randomly as requested to fulfill each request. With stateful session beans, a client will get a single bean to work with and as long as they keep the pointer to that bean they will keep getting that same bean across an entire session.
 
amit shukla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii thomas.
could you plz explain me in terms of my application..
i'm doing an application of shopping cart in which client creats the instance using his name and then client is given an unique id . client can also log in using his id now if at this point of time if server is restarted or crashes what problem will occur as client related data is loaded from the database only ...as in an entity bean.. so what we mean when we say that stateful session bean instance exists only till client session is valid ..
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An entity bean is tied directly to a Database so if client data is in an entity bean and the server crashes, the client information is recoverable. If the client was filling a shopping cart session bean when the server crashes, the shopping cart data is lost.
 
amit shukla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx paul
got your point.. If i want to use the same stateful bean instance a no of different web pages as in the shopping cart example as the client can select an item from any of the web pages and any no of web pages if Bean Client is servlet , will i have to use session tacking api or there is some other method or facility provided by the container as in each successive invokations of servlet client only doGet() is called on and on...
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use session tracking and store the pointer to the remote object.
 
amit shukla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thomas ..
thanx for such a nice discussion ..now i'm clear whtats the differece ..let me state that although session beans are called session beans but that doesn't that they have built in support for session persistence stilll we r supposed to use session tracking api..
but does that mean everytime i want to access a bean i have to create (or get a ref to it) it ..then use it for a single servlet invocation if not using the session tracking..
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but does that mean everytime i want to access a bean i have to create (or get a ref to it) it ..then use it for a single servlet invocation if not using the session tracking..

Yes.
------------------
Moderator of the JDBC Forum
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!