1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.

Slides:



Advertisements
Similar presentations
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Advertisements

Chapter 10: Designing Databases
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
CMSC424: Database Design Instructor: Amol Deshpande
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Database Management: Getting Data Together Chapter 14.
Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar.
Chapter 11 Data Management Layer Design
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Databases and Database Management Systems
Compe 301 ER - Model. Today DBMS Overview Data Modeling Going from conceptual requirements of a application to a concrete data model E/R Model.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Page 1 ISMT E-120 Introduction to Microsoft Access & Relational Databases The Influence of Software and Hardware Technologies on Business Productivity.
Entity-Relationship Design
Chapter 5 UNDERSTANDING AND DESIGNING ACCOUNTING DATA.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Relational Database Concepts. Let’s start with a simple example of a database application Assume that you want to keep track of your clients’ names, addresses,
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
Entity Beans BMP Celsina Bignoli
IS-907 Java EE JPA: Simple Object-Relational Mapping.
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
CTFS Workshop Shameema Esufali Suzanne Lao Data coordinators and technical resources for the network
RDBMS Concepts/ Session 3 / 1 of 22 Objectives  In this lesson, you will learn to:  Describe data redundancy  Describe the first, second, and third.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Database Normalization Lynne Weldon July 17, 2000.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta.
Natural vs. Generated Keys. Definitions Natural key—a key that occurs in the data, that uniquely identifies rows. AKA candidate key. Generated key—a key.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
Object Persistence (Data Base) Design Chapter 13.
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
How to build ER diagrams
Chapter 12: Designing Databases
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database Design Some of these slides are derived from IBM/Rational slides from courses on UML and object-oriented design and analysis. Copyright to the.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Information Access Mgt09/12/971 Entity-Relationship Design Information Level Design.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Data modeling Process. Copyright © CIST 2 Definition What is data modeling? –Identify the real world data that must be stored on the database –Design.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
Database Design. Database Design Process Data Model Requirements Application 1 Database Requirements Application 2 Requirements Application 4 Requirements.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
Faeez, Franz & Syamim.   Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population,
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
Database Planning Database Design Normalization.
SQL Basics Review Reviewing what we’ve learned so far…….
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Introduction to Database Programming with Python Gary Stewart
Geographic Information Systems GIS Data Databases.
Fundamentals of DBMS Notes-1.
Module 11: File Structure
Relational Model.
CIS 155 Table Relationship
Distributed Objects and object persistence
Chapter 4 Relational Databases
Translation of ER-diagram into Relational Schema
Physical Database Design
Presentation transcript:

1 Part 2: EJB Persistency Jianguo Lu

2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage Objects can't be directly saved to and retrieved from relational databases Approaches to object persistency –Java object serialization –Convert object into a byte stream and store it as a whole in database/ file system. –Object database –Objects are the 1 st class citizen in the database –Object relational mapping –This is the popular approach used in EJB

3 Relational model vs. object model from

4 Objects and relations RelationObject goal of relational modeling is to normalize data (i.e., eliminate redundant data from tables) goal of object-oriented design is to model a business process by creating real-world objects with data and behavior RDBMS stores data onlyobjects have identity, state, and behavior No inheritanceOrganized into inheritance hierarchy tables are related via values in foreign and primary keys objects are traversed using direct references

5 Mapping Entity beans to Tables Simple case –Map entities to tables –Map attributes (with primitive data types) in an entity bean to columns in the table Synchronizing the object with the table is taken care of by EJB container: SALNAME Employee Table EmployeeBean name sal findByName(n) SELECT * FROM EMP WHERE NAME=n ID ejbLoad: SELECT name, sal FROM employee WHERE id=? ejbStore: UPDATE employee SET name=?, sal=? WHERE id=? ejbPostCreate: INSERT INTO employee VALUES(?,?,?) ejbRemove: DELETE FROM employee WHERE id=?

6 Object attributes and table columns Not all attributes are mapped to table columns Describe the mapping using deployment descriptor using XML Employee name sal … … … What if the attribute in an entity bean is an entity bean itself? –E.g., Employee bean may have Address attribute –It is a relations between objects

7 Relationships between objects Aggregation –Mapping strategies –Single table aggregation –Foreign key aggregation –Manage cardinalities –Manage many-to many relations –Manage composition Inheritance –One table for one inheritance tree –One table for one class –One table for one inheritance path

8 Single Table Aggregation Pattern(1/4) Abstract: map aggregation to a relational data model by integrating all aggregated objects’ attributes into a single table. Example: CourseEdition has Instructor attribute Design pattern: a general repeatable solution to a commonly-occurring problem in software design Instructor Type : Integer SSN : Integer surName : String Age : Integer townOfBirth : String name : String CourseEdition EndDate : String StartDate : String Code : String instructor : Instructor course :Course

9 Single Table Aggregation(2/4) Solution: Put the aggregated object's attributes into the same table as the aggregating object’s. aggregatingObject aggregatedObject AggregatingTable Attributes from aggregated object table Attributes from aggregating table

10 Single Table Aggregation(3/4) Instructor Type : Integer SSN : Integer surName : String Age : Integer townOfBirth : String name : String CourseEdition EndDate : String StartDate : String Code : String instructor : Instructor course :Course CourseEditionTable EndDate : VARCHAR(0) StartDate : VARCHAR(0) Code : VARCHAR(0) course : VARCHAR(0) Type : SMALLINT SSN : SMALLINT surName : SMALLINT Age : SMALLINT townOfBirth : SMALLINT

11 Single Table Aggregation(4/4) Consequences –Performance: –Pro: only one table needs to be accessed to retrieve an aggregating object with all its aggregated objects. –Con: the fields for aggregated objects’ attributes are likely to increase the number of pages retrieved with each database access, resulting in a possible waste of I/O bandwidth. –Maintenance and flexibility: If the aggregated object type is aggregated in more than one object type, the design results in poor maintainability as each change of the aggregated type causes an adaptation all of the aggregating object types’ database tables. –Consistency of the database: Aggregated objects are automatically deleted on deletion of the aggregating objects. –Ad-hoc queries: If you want to form a query that scans all Instructor objects in the database, this is very hard to formulate.

12 Foreign Key Aggregation (1/3) Abstract: The pattern shows how to map aggregation to a relational data model using foreign keys. Solution: Use a separate table for the aggregated type. Insert an synthetic object identity into the table and use this object identity in the table of the aggregating object to make a foreign key link to the aggregated object. aggregatingObjectaggregatedObject AggregatingTable … attribute1 aggregatedObjectID AggregatedObjectTable … attribute1 ObjectID Foreign key

13 Foreign Key Aggregation (2/3) Instructor Type : Integer SSN : Integer surName : String Age : Integer townOfBirth : String name : String (from OM_Training) CourseEdition EndDate : String StartDate : String Code : String instructor : Instructor course :Course (from OM_Training) CourseEditionTable EndDate : VARCHAR(8) StartDate : VARCHAR(8) Code : VARCHAR(8) course : VARCHAR(8) Type : SMALLINT SSN : SMALLINT surName :VARCHAR(8) Age : SMALLINT townOfBirth :VARCHAR(8) InstructorTable instructorID: VARCHAR(8) Foreign key Example: Instructor and CourseEdition are mapped to two tables

14 Foreign Key Aggregation (3/3) Consequences –Performance: Foreign Key Aggregation needs a join operation or at least two database accesses where Single Table Aggregation needs a single database operation. If accessing aggregated objects is a statistical rare case this is acceptable. If the aggregated objects are always retrieved together with the aggregating object, you have to have a second look at performance here. –Maintenance: Factoring out objects like Instructor into tables of their own makes them easier to maintain and hence makes the mapping more flexible. –Consistency of the database: Aggregated objects are not automatically deleted on deletion of the aggregating objects. EJB container help maintain the consistency of CMP entity bean. BMP entity bean will need additional code to maintain consistency. –Ad-hoc queries: Factoring out aggregated objects into separate tables allows easy querying these tables with ad-hoc queries.

15 Specify relations using deployment descriptor CourseEdition … Instructor … … Instructor Type : Integer SSN : Integer surName : String Age : Integer townOfBirth : String name : String CourseEdition EndDate : String StartDate : String Code : String instructor : Instructor course :Course Instructor-CourseEdition Instructor-For One … … Instructor Courses One CourseEdition 1 1

16 Manage Cardinality: 1 to many relationships Instructor Type : Integer SSN : Integer surName : String Age : Integer townOfBirth : String name : String CourseEdition EndDate : String StartDate : String Code : String instructor : Instructor course :Course 1 n Instructor-CourseEdition Instructor-For Many Instructor Courses One … … CourseEdition courses java.util.Collection

17 Manage cardinality: many to many relationships Example A Trainee may register several CourseEditions, and one CourseEdition has a number of Trainees. Solution Create a separate table containing the object identifiers (or Foreign Keys) of the two object types participating in the association. Map the rest of the two object types to tables using any other suitable mapping pattern. Trainee-CourseEdition Trainee-EnrollIn-Courses Many Instructor courses java.util.Collection Courses-HaveEnrolled-Trainees Many CourseEdition trainees java.util.Collection

18 Manage composition Aggregation and composition –Composition is a stronger form of aggregation. –Deleting the aggregating object will also delete the aggregated object. Use cascaded delete in deployment descriptor, to indicate that deletion operation on Instructor is cascaded down to associated Telephone objects. Instructor-Telephone One … … Instructor Many … … Telephone

19 Mapping inheritance Strategies of mapping inheritance to tables: –One table for the inheritance tree –One table for each class –One table for each inheritance path

20 One table for the inheritance tree Solution: use the union of all attributes of all objects in the inheritance hierarchy as the columns of a single database table. BaseClass AttributesDescendentA AttributesDescendentB Attributes Attibute Values from BaseNull Values Attibute Values from BaseAttibute Values from ANull Values Attibute Values from BaseNull valuesAttibute Values from B Base class instance DescendentA instance DescendentB instance

21 One table for the inheritance tree Consequences –Write/update performance: Reading/writing any objects in the hierarchy with one database operation –Space consumption: Requires more space to store the objects –Maintenance cost: small

22 One table for each class Solution –Map the attributes of each class to a separate table BaseClassTable BaseClassAtrributes DescendentB Table DescendentB Attributes DescendentA Attributes DescendentA Table

23 One table for each class Consequences –Write and update performance: More database operations involved –Space consumption: has near optimal consumption –Maintenance cost: As the mapping is straightforward and easy to understand, schema evolution is straightforward and easy.

24 One table for each inheritance path Solution: –Map the attributes of each class to a separate table. To a classes’ table add the attributes of all classes the class inherits from. –If BaseClass is abstract, BaseClassTable is not generated. RightPathTable BaseClassAttributes DescendentB Attributes LeftPathTable BaseClassAttributes DescendentA Attributes BaseClassTable BaseClassAtrributes

25 One table for each inheritance path Consequences –Write and update performance: One database operation to read or write an object –Space consumption: optimal. No redundant attributes –Maintenance cost: Adding or deleting attributes of a superclass results in changes to the tables of all derived classes.