EntityBean with CMP
This article will provide you an example on how to create an Entity Bean with Container Managed Persistence.
Requirements / Tool used
- Sun Application Server
- The Entity Bean and web app code
The Entity Bean we will deploy is a simplification of the SunOne Example. An entity bean called Customer will provide access and persistence to this business object. Then we will acess this object through a web application to edit, add, remove cutomers.
First unzip the Entity Bean and Web App code and import the project in Eclipse for example.
Project structure :
├───build ├───ejb │ └───src │ └───customer │ └───util ├───lib └───war └───src
- build : contains an already created ear ready to be deployed. This is just a sample. We will create another one.
- ejb : contains source and classes for the EJB
- lib : contains some libraries, taken from the Sun One Application library folder
- war : contains sources and classes for Web App and also JSP and HTML pages
Deployment of project
STEP 1 : Database
In this example, we use Oracle DBMS. Note that we do not have to create any table : the bean is CMP so all SQL is managed by teh server. Table is automatically created, updated, ...
The only thing we must configure for the database is the JDBC Connection Pool (see STEP 3).
STEP 2 : Configure application server
- Start the application server
- Launch the dministration console
- Configure a JDBC connection pool and a JDBC resource for this pool
You can see this movie that will show you how to do that.
STEP 3 : Deploy the project
Now we must launch the DeployTool, pack all files and create descriptors. An EAR file must be created and then deployed on the server
You can see this movie explaining how to deploy :
- For IE : you can view it online (wait about 1min before clicking on play)
- For others, you can download it here (30Mo video file for more than 30min of video)
STEP 4 : Test
You should be able to create, delete and edit customer. Note : the dataabse is automatically created ;) Cool !