EJB high level
Jump to navigation
Jump to search
- Separates transaction and security metadata from bean
- Provides transaction management, state management, resource pooling, security
- if not using security or transactions question if you need EJB
EJB3
- No longer have to lookup home and do create. Bean created automatically when looked up.
- Tend to be called "Entity" in EJB 3 and "Entity Bean" in EJB 2.0
JPA
Defines:
- Creation of ORM (Object-Relational Mapping) metadata
- Entity Manager API - API for CRUD - persistence operations
- JPQL (Java persistence query language) - searching & retrieving
Designed to also exist outside application server
Entity Manager
- Reads ORM metadata
- Persists data - performs CRUD operations
- Handles life-cycle - performance tuning - cache, transaction management
JPQL
Supports:
- inner joins
- outer joins
- bulk updates
- delete
- sub queries
- Does not support full sql
Also supports native queries - exam doesn't consider this as full sql
Terminology
EJB 3
- Remote business interface - the @remote interface
- Supports annotations and deployment descriptors
- deployment descriptor overrides
- So can deploy in different environments without changing code
- deployment descriptor overrides
- No longer have to implement lifecycle callbacks
- can put lifecycle callbacks in a separate class
public class FooListener{ @PrePassivate public void doPrePassiveStuff() { .... } }
@CallbackListener FooListener @stateful public class FooBean{
EJB 2
- Remote home interface - factory for creating bean
- Component interface - clients view - interface of the bean
- remote component interface - remote proxy for accessing the bean
- local component interface (also known as local client)
- Business interface - interface implemented by the remote component interface and the bean
EJB 2
- Home - javax.ejb.EJBHome - factory pattern to create instance of EJB
- Remove - javax.ejb.EJBObject - proxy for accessing the bean
- Bean
- javax.ejb.Session - information to persist
- Stateless - Do not hold conversational state - no guarentee the client will call same bean
- Stateful - Can hold state - will be the same bean across client calls e.g. shopping basket
- also use to for workflow
- javax.ejb.Entity - the implementation containing business logic
- javax.ejb.Session - information to persist