
When developing entity beans with bean-managed persistence, you can freely manage the persistence. That is, you can write the SQL queries yourself. This is called programmatic persistence.
You use bean-managed entity beans when:
Bean-managed entity beans are more difficult to develop. If your application does not require specific coding, it is therefore recommended that you develop entity beans with container-managed persistence.
The container-managed persistence is called a declarative persistence. It is very easy to use when the object model of the persistent data is complicated. You do not have to write the SQL queries - you can use the system to generate the O/R mapping, the corresponding tables, and the SQL queries required by the persistence management that uses common JDBC types automatically. To enable the EJB Container to perform these functions, you must declare the necessary information in the bean's deployment descriptors.
Use container-managed entity beans, when:
It is easier to write container-managed entity beans because the EJB Container manages the database access, the mappings, the consistency and the integrity of the data.
As the source code of container-managed entity beans (as opposed to the source code of bean-managed entity beans) does not contain database access calls, container-managed entity beans are independent of the database and can easily be ported to different databases.
For more information about creating entity beans, see Creating Entity Beans .