Q

How do I change a stateless session bean into a stateful session bean?

How do I change a stateless session bean into a stateful session bean?
The primary design difference between a version 2.x stateful EJB and a stateless EJB is the state information is typically stored in the stateful EJB's member fields, whereas no state information should be saved in the stateless EJB.

The primary implementation difference between the two is the information specified in the EJB's deployment descriptor file (ejb-jar.xml). For example, a typical ejb-jar.xml file for a stateless EJB might look like the following:


<ejb-jar>
   <enterprise-beans>
      <session>
         <ejb-name>MyEJB</ejb-name>
         <home>com.jeffhanson.ejb.MyEJBHome</home>
         <remote>com.jeffhanson.ejb.MyEJB</remote>
         <ejb-class> com.jeffhanson.ejb.MyEJBBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-type>
      </session>
   </enterprise-beans>
   ...
</ejb-jar>
Now to turn this into a stateful EJB deployment, we just need to modify the "session-type" element to read:

<session-type>Stateful

This was first published in November 2004
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close