Java Tutorial - Java Scipt : Creating a Deployment Descriptor

Java Tutorial - Java Scipt :

Creating a Deployment Descriptor

Now, we need to modify the EJB deployment descriptor ejb-jar.xml to add our new session bean. We will start with the file we created earlier, and this time just focus on the additions needed to add our session bean. The first part of this addition is shown below. It should be added immediately after the closing

</entity> tag:
<session>
<display-name>UserSession</display-name>
<ejb-name>UserSession</ejb-name>
<home>com.oldfriends.session.UserSessionHome</home>
<remote>com.oldfriends.session.UserSessionRemote</remote>
<ejb-class>com.oldfriends.session.UserSessionEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>

The values here are almost identical to those we have already discussed for the entity bean. There are a couple of differences here. The <session-type> can be either Stateless or Stateful. Ours is a stateless bean. The transaction
type is set for the container to manage transactions. The next section, which follows, is the <ejb-local-ref> element, which is needed so that we can find the entity bean:

<ejb-local-ref>
<ejb-ref-name>ejb/LocalUserEJB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>com.oldfriends.entity.UserLocalHome</local-home>
<local>com.oldfriends.entity.UserLocal</local>
<ejb-link>UserEJB</ejb-link>
</ejb-local-ref>

The <ejb- ref-name> value should be set to the JNDI name that is used in our code to retrieve the LocalHome interface of the entity bean. The <ejb-link> provides the connection between this JNDI name and the entry for the bean. This will be used in the jboss.xml file to complete the JNDI mapping. The <ejb-ref-type> tells the container whether we are referencing an entity bean or a session bean. The <local-home> and <local> elements provide the fully qualified class names for the LocalHome and local interfaces for the bean we are referencing. The next section is also a reference, but it is a resource reference that will be used to get the DataSource from the container, as you can see in the following code:

<resource-ref>
<description>DataSource for oldfriends database</description>
<res-ref-name>java:/jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Sharable</res-sharing-scope>
</resource-ref>
</session>

The <res-ref-name> is the JNDI name that we use in our code to get the DataSource. The <res-type> element provides the fully qualified class name of the class that is returned by the lookup. The <res-auth> element says that the container has the responsibility for providing username and password needed to generate connections from the DataSource. Finally, <res-sharing-scope> says that this resource is sharable with other beans. The </session> tag ends the changes to the ejb-jar.xml file.