When using Container Managed Persistence, you are not supposed to write database code in your Entity bean. All the persistence mechanism is handled by the container. This also means that your beans are more flexible. You can easily change the J2EE server and the database. Container will take care of all the thing related to persistence.