2

As I see in examples, every java class can be defined as a session bean in ejb, even if there is no http session defined and used inside them. So, why are they called session beans?

Alex Hero
  • 57
  • 1
  • 4
  • 1
    Well, it's not called `HttpSessionBean`. There are other sessions. – Keppil Jun 02 '13 at 11:10
  • Indeed, "session" != "HTTP session". A "session" is just the context wherein multiple closely related requests/conversations/queries/etc can take place. In case of EJBs, a single "session" must be interpreted in context of a single DB transaction (while in case of HTTP, a single session must be interpreted in context of a single webbrowser instance). Related: http://stackoverflow.com/questions/8887140/jsf-request-scoped-bean-keeps-recreating-new-stateful-session-beans-on-every-req/8889612#8889612 – BalusC Sep 05 '13 at 18:07

2 Answers2

2

A session bean performs operations, such as calculations or database access, for the client. . Session bean objects either can be stateless or can maintain conversational state across methods and transactions.

A stateless session bean is an object that does not have an associated conversational state, but may have instance state

In Stateful session bean, the instance variables represent the state of unique client-bean sessions. The interaction of the client with bean is called as conversational state.

No matter whether a session bean is statelss or stateful they mantain some kind of session, which may last for a single call or may last for mulitple bean calls. Hence they are called Session beans.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
1

They could also somewhat less accurately have been called "transaction" beans. Each entry-point method is executed within the context of an isolated session with a back-end system, which is most typically, but not necessarily, a database.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436