Stateless Session Bean vs Stateless Singleton

I am new to EJB and recently started working on EJB (3.0). I have been using Java for 6 years, but have not worked with EJB before. I am at least stunned by the complexity of the entire EJB business. I do not understand where I can practically apply some of the concepts.

One question that comes to my mind after understanding a session without a bean state: Can you not always replace a session without a bean with a common instance of the class without local members (which makes it inactive)? I read that instance merging is done for a session without beans state. If there is no state, can't you just use one instance?

I am deploying my samples in OpenEJB and in one place where I had to use a session without a bean state was to interact with EntityManager. I'm not sure if I can handle the EntityManager in an arbitrary class. In addition to this, the question of what is trying to solve the problem of an idle bean is still puzzled.

+3
source share
3 answers

A session without a bean can have a state. But he may not have a conversational state . Therefore, it is acceptable that the bean session method does the following (albeit bad practices):

public void foo() {
    this.someVar = bar();
    this.someOtherVar = baz();
    zing();
}

In addition to pooling, the EJB container provides several services without apathy beans:

  • dependency injection
  • declarative transaction demarcation
  • declarative security
  • access to the EJB context
  • .

, bean .

+10

, beans , . EJB POJO, beans .. , bean .

bean , , .

+4

EntityManager , , .

EJB EJB, .

, EJB , . , , EJB, ..

, " ", , ?

beans - . Java EE 3 : 1. 2. 3.

EJB Businness. SLSB SFSB. , . -, SFSB . , -, , SFSB. SLSB SFSB EntityManager , SLSB . EJB3 JPA - . , .

0

All Articles