Monday, December 14, 2015

Business Component Development with EJB Technology - Module 04

Module 4

 Implementing Entity Classes: The Basics


Objectives

Upon completion of this module, you should be able to:

  • Examine Java persistence 
  • Define entity classes: Essential tasks 
  • Manage entity instance life-cycle states 
  • Deploy entity classes



Examining Java Persistence
  • What is data persistence? 
  • What is the Java persistence specification? 
  • How does the Java Persistence API relate to Java EE application servers? 
  • What are the key features of the persistence model specified in the Java Persistence API?


Static Relationship Mapping - Data Tier Elements




Static Relationship Mapping - Object Tier Elements




Dynamic Relationship - Object / Data Tier Data Synchronization


With entities, the data synchronization is maintained by the persistence provider.


EntityClassExample



Declaring the Entity Class

1. Collect information required to declare the entity class. 
2. Declare a public Java technology class. 
3. Implement Serializable if required. 
4. Do not include a finalize method. 
5. Use Entity annotation. 
6. Declare attributes. 
7. Optionally declare get and set methods. 
8. Designate primary key using the Id annotation. 
9. Declare no- arg constructor.


Entity Code Example


Corresponding CUSTOMER table:



Verifying and Overriding Default Mapping
  • Table annotation 
@Entity 
@Table(name=”Cust”)//Cust is the name of the database table 
public class Client { 
  • Column annotation 
@Entity 
@Table(name=”Cust”) public class Client { 
@Column(name=”cname”) 
private String clientName; 
  • Lob annotation 
26     @Lob 
27     @Column(name="PHOTO" columnDefinition="BLOB NOT NULL") 
28     protected JPEGImage picture;


Examining Managing Entity Instance Life Cycle States
  • Entity life-cycle states 
                          New 
                          Managed 
                          Detached 
                          Removed 
  • Entity manager 
  • Persistence contexts 
  • Persistence identity

Entity Instance State Diagram




Changing Entity Life - Cycle States



Other Entity Manager Methods




Persistence Contexts
  • What causes a persistence context to end? 
                   •Transaction scoped 
                   •Extended scoped 
  • How is a persistence context created? 
  • How is an extended scoped entity managerc reated in a Java EE container? 
  • How is a transaction scoped entity manager created in a Java EE container? 
  • What tasks are relevant to managing the life - cycle state of an entity instance?


Entity Instance Management Using Transaction Scoped Persistence Context



Entity Instance Management Using Extended Scoped Persistence Context



Deploying Entity Classes
  • What is a persistence unit?
  • Where should components of the persistence unit be placed?

Default Locations for Persistence Unit Components



Example of Persistence Unit Components in Default Settings





No comments:

Post a Comment