Creating and Removing Entity Beans
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Bean Annotation
Table
Tutorials

CMP Field
Transactions
CMP Basic
CMP Create
CMP Transactions
CMP Query
CMP Many-to-One
CMP One-to-Many
CMP Many-to-Many
CMP Inherit
Stateless Session
CMP Basic
Tutorials
CMP Transactions

Find this tutorial in: /usr/local/resin/resin-3.0.12/webapps/resin-doc/ejb3/tutorial/cmp-create
Try the Tutorial

Describes the basic create/remove api for entity beans.

  1. Files in this tutorial
  2. Database Schema
  3. Client Servlet

Almost all applications need to add and remove entities from the database. Although most database accesses are reads, eventually we need to change the database. With CMP, you create a new instance with the following steps:

  1. Instantiate the instance with "new"
  2. Populate the values
  3. Call the EntityManager create method

Files in this tutorial

WEB-INF/web.xml web.xml configuration
WEB-INF/classes/example/Course.java The course bean
WEB-INF/classes/example/CourseServlet.java The course servlet

Database Schema

The example uses the same database table as the previous basic example.

create.sql
CREATE TABLE create_courses (
  id BIGINT PRIMARY KEY auto_increment,
  course VARCHAR(250),
  instructor VARCHAR(250)
);

Client Servlet

Clients create a new bean and populate the fields just like a normal Java object. The client adds the entry to the database by calling the EntityManager's create method.

Adding and Removing Courses
...

divination = new Course("Divination", "Sybil Trelawney");
_entityManager.create(divination);

...

_entityManager.remove(divination);
...

Try the Tutorial


CMP Basic
Tutorials
CMP Transactions
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.