␡
- Entity Bean
- Session Bean
- Message Bean
- Relationships
- Going Forward
Like this article? We recommend
Session Bean
The tags involved in creating a session bean are mostly a subset of those used to create an entity bean. All the tags that are required are the same as for an entity bean. Therefore just an example of a session bean should be sufficient:
package com.dzrealms.example.entity; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.ejb.CreateException; /** * @ejb.bean name="ExampleSessionBean" * jndi-name="example/remote/ExampleSession" * local-jndi-name="example/local/ExampleSession" * * @ejb.interface * remote-class="com.dzrealms.example.entity.ExampleSessionRemote" * local-class="com.dzrealms.example.entity.ExampleSessionLocal" * * @ejb.home * remote-class="com.dzrealms.example.entity.ExampleSessionRemoteHome" * local-class="com.dzrealms.example.entity.ExampleSessionLocalHome" */ public class ExampleSessionBean implements SessionBean { /** * @ejb.create-method * @throws CreateException */ public void ejbCreate() throws CreateException { } /** * @ejb.interface-method */ public void doSomethingUseful() { } public void setSessionContext(SessionContext context) { } public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } }
The tags involved for a session bean are extremely straightforward. Other than defining the names for the interfaces and the jndi, there is nothing else involved. After the class tags are defined, it is just a matter of adding the methods to the interfaces as needed.