Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company docs 
app server 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

creating and removing entity beans


Describes the basic create/remove api for persistent entities.

Demo

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 Amber, you create a new instance with the following steps:

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

Files in this tutorial

WEB-INF/resin-web.xmlresin-web.xml configuration
WEB-INF/classes/META-INF/persistence.xmlpersistence.xml configuration
WEB-INF/classes/example/Course.javaThe course bean
WEB-INF/classes/example/CreateServlet.javaThe create 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 persist method.

Adding and Removing Courses
...

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

...

_entityManager.remove(divination);
...

Demo


Copyright © 1998-2015 Caucho Technology, Inc. All rights reserved. Resin ® is a registered trademark. Quercustm, and Hessiantm are trademarks of Caucho Technology.

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).
Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.

home company docs 
app server