8.3. Lifecycle Examples

The examples below demonstrate how to use the lifecycle methods
presented in the previous section. The examples are appropriate for
out-of-container use. Within a container,
EntityManagers are usually injected, and transactions are
usually managed. You would therefore omit the
createEntityManager and close
calls, as well as all transaction demarcation code.