I am trying to figure out an old and quite bit-rotten EJB 2.0 application, with a migration to EJB 3.x being a future possibility.

EJB 3.x is nice enough to keep its bean definitions compact and use annotations for important metadata. Unfortunately, EJB 2.x is definitely more complex, with several XML files heaped upon each other. Add some JBoss-specific method calls and the corresponding XML files and the result is a mess...

So, starting from the basics:

How could one reliably tell stateful and stateless EJB 2.0 beans apart?

有帮助吗?

解决方案

An important piece of information is the content of the ejb-jar.xml file. It may contain explicit elements w.r.t. a bean being stateful or not.

For a stateful bean:

<session>
   ...
   <ejb-name>TestBean</ejb-name>
   ...
   <ejb-class>com.example.TestBean</ejb-class>
   <session-type>Stateful</session-type>
   ...
</session>

For a stateless bean:

<session>
   ...
   <ejb-name>TestBean</ejb-name>
   ...
   <ejb-class>com.example.TestBean</ejb-class>
   <session-type>Stateless</session-type>
   ...
</session>

Other important indications can be found in the bean implementation. According to the EJB 2.0 specification, section 7.5.3:

A stateless Session bean must not implement the SessionSynchronization interface.

From section 7.8, on stateless beans:

The session bean class must define a single ejbCreate method that takes no arguments.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top