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 Resin-EE, you add a create method with the following steps:
method to the local home interface.
method in the bean class, setting any database fields.
method in the bean class, setting any bean relations if necessary.
The example uses the same database table as the previous basic example.
Clients simply call the create method from the CourseHome interface. The following servlet fragment creates two new courses, prints all the courses, and then removes the new courses.
remove() method is generated automatically and is
always part of the
interface. All we need to do is
interface adds the
Most than one create method is allowed, but all must start with create.
would be allowed.
Any create method must throw
Creating a bean needs to methods in the bean class:
saves cmp-fields before inserting
into the database.
links persistent relations. In this
method will be empty. In the example of
user comments to an article, the
method will link the
new comment object to the owning article.
sets the primary key and cmp-fields
sets the cmr-fields (relations to other beans)
method is the only method that may call the setter
for the primary key. Database tables which generate their own
primary key (e.g. autoincrement ids), will have no setter for the