Here are the methods defined in EJB (Enterprise JavaBeans):
1) ejbCreate( ), ejbPostCreate( ) methods: It is used for creating a new entity bean instance. INSERT statement is executed and a new row is inserted in the database.
2) ejbLoad( ) method: It is used for loading values of instance variables. SELECT statement is executed and data is read from the database.
3) ejbStore( ) method: It is used for storing values of instance variables. UPDATE statement is executed and data is stored in the database.
4) ejbRemove( ) method: It is used for removing a entity bean instance. DELETE statement is executed and data is removed from the database.
Bean managed persistence: Bean managed persistence can be specified in an entity bean’s deployment descriptor. In this process the entity bean itself handles the interaction with the database. For Example: For creating a new entity bean, container calls ejbCreate( ) and ejbPostCreate( ) methods and bean processes INSERT statement.
Container managed persistence: In this process the container handles the interaction with the database. Here, container uses JDBC for updating the instance variables and to read/write data in database.
Disadvantages of container managed persistence:
1) Container managed persistence cannot be used if entity bean data is coming from multiple databases.
2) Performance is reduced when container managed persistence is used.
3) Container managed persistence works well only when instance variables for an entity bean are from a one row of a table. For complex situations where two or more tables are involved container managed persistence is not used.
4) Container managed persistence generates redundant results where complex database queries are involved.