Writing ejbCreate() methods for bean-managed persistence
Objective
Explore the code for the ejbCreate() methods in an entity bean
Writing ejbCreate() methods
Each create() method in the home interface maps to an equivalent ejbCreate() method in the bean, just as they do for session beans. The methods are mapped through their parameters, which must match in type and number.
Primary Key is returned
Each ejbCreate() method, using its arguments, creates the
underlying persistent entity object. The method uses JDBC, or some similar technique supported by the EJB platform, to
create the data, and when finished, returns the primary key of the entity object that it created. The Customer example
in this module uses a String as the primary key to make the code samples in the course more simple. This makes it
easier to see how the code works. The String contains an integer that is used as the primary key for the new entity
object. The following MouseOver illustrates the code:
The ejbCreate(custnum, name) has a very similar code. The only difference is that the name parameter is stored in the newly created row.
The next lesson introduces the ejbPostCreate() method.