In the previous post, Introduction to Stateful Session Bean in NetBeans, we covered how to develop a stateful session bean. This tutorial picks up from there and shows how to call the business methods of that stateful session bean from a Java class.
Step-by-Step Instructions
- Open the enterprise application where your session bean EJB module resides.
- Create a simple Java class within the project.
- In the Java class, right-click and select Enterprise Resources → Call Enterprise Bean.
- The IDE presents a dialog with the option "Generate Inline Lookup Code" — this generates the JNDI lookup code directly in your class rather than in a separate helper.
- Select the target EJB from the list of deployed enterprise beans and proceed. NetBeans inserts the lookup and home/remote interface code automatically.
- Edit the generated code to invoke the specific business methods exposed by your stateful session bean.
Important: The EJB must be deployed to the application server before you attempt to run the calling class. Ensure the server is running and the module is deployed successfully.
Once the code is ready, run the Java class (typically with Shift+F6) to execute the call and observe the results in the server log or console output.