Deploying Entity Bean on JBoss 5

Hello everyone, Now a days I am trying my hands on EJB 3.0. I have been experimenting
with EJB 3.0 on JBoss application Server. I went on many forums and found that some of
you people are facing problems deploying Entity Beans same as I did in the begining,
So i thought of writing on it n giving a working example.
I have gone through “Enterprise java beans 3.0” book by oreilly. its a very nice book.
My example is also from the same book.
I will start with the example as you people can go through the definition n all from
the book. Though you can get this code from book too m also writng it so that everything
should be in a rytdhm 😛

One more thing you can code entity bean either using annotations or by specifying the
mappings in a mapping file named “orm.xml”. I will give an example based on the mapping
file, I you guys want an example using annotations refer to the unlined link. He is my
colleague and a good friend, he has explained clearly about the example and much more
concepts of the entity beans.

we will start with code now
This is our customer class : ENTITY BEAN

package com.titan.domain;
* @author bhupesh
public class Customer implements Serializable {
private int id;
private String firstName;
private String lastName;
public int getId() {
return id;
public void setId(int id) { = id;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;

We Will need a session bean which will be responsible for persisting the object into
the database, though the actual work is done by an ENTITY MANAGER
package com.titan.travelagent;
import com.titan.domain.Customer;;
* @author bhupesh
public interface TravelAgentRemote {
public void createCustomer(Customer p);
public Customer findCustomer(int id);
package com.titan.travelagent;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.titan.domain.Customer;
* @author bhupesh
public class TravelAgentBean {
@PersistenceContext(unitName=”titan”)private EntityManager manager;
public void createCustomer(Customer cust){
public Customer findCustomer(int id){
return manager.find(Customer.class, id);

ORM Mapping file is :
<?xml version=”1.0″ encoding=”UTF-8″?>
<orm:entity-mappings version=”1.0″
xsi:schemaLocation=” orm_1_0.xsd “>
<orm:description>ORM file for mapping Customer entity!</orm:description>
<orm:entity access=”PROPERTY” class=”com.titan.domain.Customer” name=”customer”>
<orm:table name=”CUSTOMER_INFO” />
<orm:id name=”id”>
<orm:column name=”id” nullable=”false” column-definition=”integer”/>
<orm:basic name=”firstName” >
<orm:column length=”20″ name=”FIRST_NAME” nullable=”false” />
<orm:basic name=”lastName” >
<orm:column length=”20″ name=”LAST_NAME” nullable=”false” />

Now we also need a persistence.xml file which goes into the META-INF directory
here is it :

<persistence:persistence version=”1.0″
xsi:schemaLocation=” persistence_1_0.xsd “>
<persistence:persistence-unit name=”titan”>
Persistence unit name is titan
<persistence:property name=”” value=”create” />
<persistence:property name=”hibernate.dialect” value=”org.hibernate.dialect.Oracle9iDialect” />

Note one thing
you have to give like this. Firstly I tried by giving only “orm.xml” and when I packaged &
deployed the jar it gave an error stating that the mapping file could not be found.
Then i tried another bad thing, i put this file into the src directory which ultimately came into
the bin folder. When I deployed the jar to my surprise it worked. 😛 Anyway its not a good
programming practice. So i tried giving in the above way META-INF/orm.xml and it worked fine.

JAR Structure

Thats all about in how to deploy Entity Beans on JBoss 5. Wait for more to come in EJB 3.0
If you still have any queries then feel free to contact me.