As I mentioned above there are three types of beans
- Session beans
- Message-Driven beans
- Entities
Session beans are invoked by a client to perform a specific business task (check bank balance), a session bean is available for a "unit of work" and thus will not survive a server crash or shutdown. There are two types of session bean
- Stateful - automatically saves state information between client invocations without having to write additional code, i.e a shopping cart
- Stateless - do not maintain state information and model app services that can be completed in a single client invocation i.e check bank balance
Before we discuss entities we need to discuss the Java Persistence API (JPA), persistence is the ability to have data contained in Java objects automatically stored in a relational database like Oracle, this is managed by the JPA. It uses a technique called Object-Relational Mapping (ORM) which essentially maps's data held in Java objects to the database tables using configuration, so you do not have to write low-level JDBC code. Since JPA standardizes ORM frameworks for the Java Platform you can plugin ORM products like JBoss Hibernate, Oracle TopLink, etc. The JPA defines a standard for
- The creation of ORM configuration metadata for mapping entities to relational tables
- The EntityManager API - a standard API for performing CRUD (create, read, update, delete)/persistence operations for entities
- The Java Persistence Query Language (JPQL) for searching and retrieving persisted application data.
- Relationships
- Inheritance
- Polymorphism
- JPA - handles lifecycle management, performance tuning, caching, transaction management
- EntityManager - can add, delete, update and retrieve entities from the database.