Understanding Impact of J2EE On Relational Databases Donald Smith, Technology Director Dennis Leung, VP Engineering Oracle Corporation 40038:

Slides:



Advertisements
Similar presentations
January 30, 2014 Copyright Jim Farley Beyond JDBC: Java Object- Relational Mappings Jim Farley e-Commerce Program Manager GE Research and Development
Advertisements

Copyright © SoftTree Technologies, Inc. DB Tuning Expert.
Jonathan Maron Principal Product Manager Oracle Corporation.
Chapter 10: Designing Databases
TopLink: Now and in the future, O-R Mapping Product of Choice Doug Clarke Principal Product Manager, Oracle9iAS TopLink Oracle Corporation.
Apache Struts Technology
Advantage Data Dictionary. agenda Creating and Managing Data Dictionaries –Tables, Indexes, Fields, and Triggers –Defining Referential Integrity –Defining.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
G O B E Y O N D C O N V E N T I O N WORF: Developing DB2 UDB based Web Services on a Websphere Application Server Kris Van Thillo, ABIS Training & Consulting.
Technical Architectures
Layered Architectures The objectives of this chapter are: To understand the principles and importance of Layered Architectures To explain the structure.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Chapter 11 Data Management Layer Design
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
Simplify your Job – Automatic Storage Management Angelo Session id:
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
N-Tier Architecture.
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Architecture of Enterprise Systems: Domain Model and Database layer
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Hong Kong JUG March 2004 Java Persistence Issues Dennis Leung Oracle Corporation.
1 INTRO TO BUSINESS COMPONENTS FOR JAVA (BC4J) Matt Fierst Computer Resource Team OracleWorld Session
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
IMS 4212: Distributed Databases 1 Dr. Lawrence West, Management Dept., University of Central Florida Distributed Databases Business needs.
PowerTier EJB in High-Performance Applications John Killoran European Technical Services Manager Persistence Software.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
What is Sure BDCs? BDC stands for Batch Data Communication and is also known as Batch Input. It is a technique for mass input of data into SAP by simulating.
A DBA Perspective on J2EE Debu Panda Principal Product Manager Oracle Corporation Session id:
Entity Beans BMP Celsina Bignoli
Middleware Technology (J2EE/EJB) Entity Bean. 2 Introduction to Entity Beans Persistence Concepts Entity beans are persistent objects that can be stored.
Database Technical Session By: Prof. Adarsh Patel.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
J2EE Structure & Definitions Catie Welsh CSE 432
8/15/2003System Specialists Corporation How to implement BC4J with the Struts Framework Eugene Sicat Technical Architect/Project Manager System Specialists.
Information System Development Courses Figure: ISD Course Structure.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Lecture # 3 & 4 Chapter # 2 Database System Concepts and Architecture Muhammad Emran Database Systems 1.
Carey Probst Technical Director Technology Business Unit - OLAP Oracle Corporation.
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
Workforce Scheduling Release 5.0 for Windows Implementation Overview OWS Development Team.
Metadata By N.Gopinath AP/CSE Metadata and it’s role in the lifecycle. The collection, maintenance, and deployment of metadata Metadata and tool integration.
Session 1 Module 1: Introduction to Data Integrity
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Building J2EE Applications Based on Design Patterns with Business Components for Java Olivier LE DIOURIS Principal Product Manager Oracle Corporation.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
ISC321 Database Systems I Chapter 2: Overview of Database Languages and Architectures Fall 2015 Dr. Abdullah Almutairi.
Best 3 Software Development Languages. Hibernate Training Hibernate is a high-performance object-relational mapping tool and query service. Hibernate.
Running a Forms Developer Application
N-Tier Architecture.
LOCO Extract – Transform - Load
POOL persistency framework for LHC
Introduction to J2EE Architecture
ADO.NET Entity Framework
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Knowledge Byte In this section, you will learn about:
Understanding and Designing with EJB
Developing and testing enterprise Java applications
Object Relational Mapping Tools
Enterprise Java Beans.
Presentation transcript:

Understanding Impact of J2EE On Relational Databases Donald Smith, Technology Director Dennis Leung, VP Engineering Oracle Corporation 40038:

About the audience…  Who considers themselves first and foremost to be a DBA or “Database expert”?  Who considers themselves first and foremost to be a Java developer?  Who considers themselves first and foremost to be an Architect?  Who considers themselves first and foremost to be a manager, and will you admit it?

Purpose of this Session Learn and understand the impact that J2EE has on Relational Databases and how to minimize this impact.

J2EE Apps and Relational Data  J2EE is one of the leading technologies used for building n-tier, web applications – J2EE based on object technology  Relational databases are the most common data source accessed by J2EE apps  They are diverse technologies that need to be used together  This talk identifies a few of the issues to be considered

Underestimation Managing persistence related issues is the most underestimated challenge in enterprise Java today – in terms of complexity, effort and maintenance

BrowserDevice Simple Enterprise Architecture Oracle Application Server Oracle Database Server Any ClientRun Your Applications Manage Your Data

Enterprise App Architecture Focus of attention Web Server, Content Server, Distribution Server

J2EE Architectures  J2EE Architecture Options – Servlets – JSP – Session Beans – Message Driven Beans – Web Services  Bottom Line – Java application needs to access relational data somehow…

JDBC  Java standard for accessing databases  JDBC is simply the database connection utilities Java developers need to build upon SQLrows JDBC

J2EE Access of Relational Data  Direct JDBC – Direct SQL calls, uses rows and result sets directly  Object view – Accessed as objects or components, transparent that the data is stored in relational database – Need persistence layer in middle tier to handle the object-relational mapping and conversion – Focus of this talk

Impedance Mismatch  The differences in relational and object technology is known as the “object-relational impedance mismatch”  Challenging problem to address because it requires a combination of relational database and object expertise

Impedance Mismatch FactorJ2EERelational Databases Logical Data Representation Objects, methods, inheritance Tables, SQL, stored procedures ScaleHundreds of megabytesGigabytes, terabytes RelationshipsMemory referencesForeign keys UniquenessInternal object idPrimary keys Key SkillsJava development, object modeling SQL, Stored Procedures, data management ToolsIDE, Source code management, Object Modeler Schema designer, query manager, performance profilers, database configuration

Object Level Options  Depends on what component architecture is used: – Entity Beans BMP – Bean Managed Persistence – Entity Beans CMP – Container Managed Persistence – Access Java objects via Persistence Layer  Can be off the shelf or “home-grown”

ejbLoad() - “load yourself” ejbStore() - “store yourself” ejbCreate() - “create yourself” findBy…() - “find yourself” ejbRemove() - “remove yourself” Entity Beans - BMP  In BMP, developers write the persistence code themselves  Database reads and writes occur in specific methods defined for bean instances  The container calls these methods - usually on method or transaction boundaries

Entity Beans - CMP  Persistence is based on information in the deployment descriptors – More “automatic” persistence – managed by the Application Server, can be faster than BMP – No special persistence code in the bean – Description of the persistence done with tools and XML files  Less control, persistence capabilities are limited to the functionality provided. – Very difficult to customize or extend CMP features as it is built-in – Do have options to plug-in a 3 rd party CMP solution on an app server

Object Persistence Layer  Abstracts persistence details from the application layer, supports Java objects/Entity Beans SQLrows Objects Persistence Layer Objects object-level querying and creation results are objects results are returned as raw data API uses SQL or database specific calls object creation and updates through object-level API J2EE & Web Services JDBC

General J2EE Persistence Interaction  Application business objects/components are modeled and mapped to relational data store  Java business objects/Entity Beans are created from relational data  Objects are edited, traversed, processed, created, deleted, cached, locked etc  Store objects on the database  Multiple concurrent clients sharing database connections

J2EE Developer Desires  Data model should not constrain object model  Don’t want database code in object/component code  Accessing data should be fast  Minimize calls to the database – they are expensive  Object-based queries – not SQL  Isolate J2EE app from schema changes  Would like to be notified of changes to data occurring at database

DBA Desires  Adhere to rules of database (referential integrity, stored procedures, sequence numbers etc.)  Build the J2EE application but do NOT expect to change schema  Build the J2EE application but the schema might change  Let DBA influence/change database calls/SQL generated to optimize  Be able to log all SQL calls to database  Leverage database features where appropriate (outer joins, sub queries, specialized database functions)

Differences  Desires are contradictory – “Insulate application from details of database but let me leverage the full power of it” – Different skill sets – Different methodologies – Different tools  Technical differences must also be considered!

How Are Databases Affected?  In reality, it’s almost the other way around, J2EE app is influenced by database, since RDBs are the more mature technology – Database “rules” need to be followed – Object model may be influenced by data model – Database interaction must be optimized for performance – “Source of truth” for data integrity is database, not app server – Existing business logic in database

Basic J2EE Persistence Checklist  Mappings  Object traversal  Queries  Transactions  Optimized database interaction  Locking  Caching  Database features

Mapping  Object model and Schema must be mapped – True for any persistence approach  Most contentious issue facing designers – Which classes map to which table(s)? – How are relationships mapped? – What data transformations are required?

Good and Poor Mapping Support  Good mapping support: – Domain classes don’t have to be “tables” – References should be to objects, not foreign keys – Database changes (schema and version) easily handled  Poor mapping support: – Classes must exactly mirror tables – Middle tier needs to explicitly manage foreign keys – Classes are disjoint – Change in schema requires extensive application changes

Mapping Tools  Lots of mapping tools out there, however don’t get fleeced by a slick GUI  The underlying mapping support is what’s important

Business Objects Should Not Require Foreign Key Knowledge CUST_TABLE ID... AD_ID ADD_TABLE ID... PHN_TABLE IDEID Customer id : int addressID : int getAddress() getPhones() Address id : int Phone id : int ownerID : int

Should Just Reference Objects Not Foreign Keys Customer id: int address: Address phones: Collection Address id: int Phone id: int owner: Customer * CUST_TABLE ID... A_ID ADD_TABLE ID... PHN_TABLE IDE_ID

Data and Object Models  Rich, flexible mapping capabilities provide data and object models a degree of independence  Otherwise, business object model will force changes to the data schema or vice-versa  Often, J2EE component models are nothing more than mirror images of data model – NOT desirable

Simple Object Model Customer id: int name: String creditRating: int Address id: int city: String zip: String * 1:1 Relationship

Typical 1-1 Relationship Schema CUST IDNAME A_ID C_RATING ADDR IDCITYZIP

Other possible Schemas… CUST IDNAMEC_RATE C_ID ADDR IDCITYZIP CUST IDNAMEC_RATING C_ID ADDR IDCITYZIP A_ID CUST_ADDR C_ID CUST IDNAMECITY ZIPC_RATING

Even More Schemas… CUST IDNAME A_ID ADDR IDCITYZIP CUST_CREDIT ID C_RATING CUST IDNAME ADDR IDCITYZIP CUST_CREDIT ID C_RATING A_ID CUST IDNAME ADDR IDCITYZIP CUST_CREDIT ID C_RATING A_ID CC_ID CUST IDNAME CUST_CREDIT IDC_RATING ADDR IDCITYZIPC_ID CUST IDNAME CUST_CREDIT ID C_RATING ADDR IDCITYZIPC_ID

Mapping Summary  Just showed nine valid ways a 1-1 relationship could be represented in a database – Most persistence layers and application servers will only support one  Without good support, designs will be forced  Imagine the flexibility needed for other mappings like 1-M and M-M

Object Traversal – Lazy Reads  J2EE applications work on the scale of a few hundreds of megabytes  Relational databases routinely manage gigabytes and terabytes of data  Persistence layer must be able to transparently fetch data “just in time”

Just in Time Reading – Faulting Process Customer Order Proxy 1. Accessing relationship for first time 2. Get related object based on FK 3b. SQL if not cached 3a. Check Cache 4. Plug result into Proxy Order

Object Traversals  Even with lazy reads, object traversal is not always ideal – To find a phone number for the manufacturer of a product that a particular customer bought, may do several queries:  Get customer in question  Get orders for customer  Get parts for order  Get manufacturer for part  Get address for manufacturer – Very natural object traversal results in 5 queries to get data that can be done in 1

N+1 Reads Problem  Many persistence layers and application servers have an N+1 reads problem  Causes N subsequent queries to fetch related data when a collection is queried for  A side effect of the impedance mismatch and poor mapping and querying support in persistence layers

N+1 Reads Problem Pool of Created Objects or Beans Persistence Layer or EJB Container findByCity() 1 2 For each Customer Fetch their Address Address n Returns collection n If Address had related objects, they too may be fetched 2n+1 Reads! Container returns results C C CC

N+1 Reads  Must have solution to minimize queries  Need flexibility to reduce to 1 query, 1+1 query or N+1 query where appropriate – 1 Query when displaying list of customers and addresses – known as a “Join Read” – 1+1 Query when displaying list of customers and user may click button to see addresses – known as a “Batch Read” – N+1 Query when displaying list of customers but only want to see address for selected customer

Queries  Java developers are not usually SQL experts – Maintenance and portability become a concern when schema details hard-coded in application  Allow Java based queries that are translated to SQL and leverage database options – EJB QL, object-based proprietary queries, query by example

Queries  Persistence layer handles object queries and converts to SQL  SQL issued should be as efficient as written by hand  Should utilize other features to optimize – Parameter binding, cached statements  Some benefits to dynamically generated SQL : – Ability to create minimal update statements  Only save objects and fields that are changed – Simple query-by-example capabilities

Query Requirements  Must be able to trace and tune SQL  Must be able use ad hoc SQL where necessary  Must be able to leverage database abilities – Outer joins – Nested queries – Stored Procedures – Oracle Hints

Cascaded Deletes  Cascaded deletes done in the database have a real effect on what happens at J2EE layer  Middle tier app must: – Be aware a cascaded delete is occurring – Determine what the “root” object is – Configure persistence settings or application logic to avoid deleting related objects already covered by cascaded delete

Database Triggers  Database triggers will be completely transparent to the J2EE application  However, their effects must be clearly communicated and considered  Example: Data validation –> audit table – Objects mapped to an audit table that is only updated through triggers, must be read-only on J2EE

Database Triggers  More challenging when trigger updates data in the same row and the data is also mapped into an object  Example: Annual salary change automatically triggers update of life insurance premium payroll deduction – J2EE app would need to re-read payroll data after salary update OR – Duplicate business logic to update field to avoid re-read – Saves a DB call but now business logic in 2 places

Referential Integrity  Java developers manipulate object model in a manner logical to the business domain  May result in ordering of INSERT, UPDATE and DELETE statements that violate database constraints  Persistence layer should automatically manage this and allow options for Java developer to influence order of statements

Transaction Management  J2EE apps typically support many clients sharing small number of db connections  Ideally would like to minimize length of transaction on database Time Begin Txn Commit Txn Begin Txn Commit Txn

Caching  Any application that caches data, now has to deal with stale data  When and how to refresh?  Will constant refreshing overload the database?  Problem is compounded in a clustered environment  App server may want be notified of database changes

Caching 1. OO Query 4. SQL Query (if needed) 5. Results(s) 2. Does PK for row exist in cache? 3. YES – Get from Cache 6. NO – Build bean/object from results Return object results

Locking  J2EE developers want to think of locking at the object level  Databases may need to manage locking across many applications  Persistence layer or application server must be able to respect and participate in locks at database level

Optimistic Locking  DBA may wish to use version, timestamp and/or last update field to represent optimistic lock – Java developer may not want this in their business model – Persistence layer must be able to abstract this  Must be able to support using any fields including business domain

Pessimistic Locking  Requires careful attention as a JDBC connection is required for duration of pessimistic lock  Should support SELECT FOR UPDATE [NOWAIT] semantics Time Begin Txn Commit Txn Begin Txn Commit Txn Pess Lock

Other Impacts  Use of special types – BLOB, Object Relational  Open Cursors  Batch Writing  Sequence number allocations

Summary  J2EE apps accessing relational databases: – Don’t need to compromise object/data model – Need to fully understand what is happening at database level – Can utilize database features – Do not have to hard code SQL to achieve optimal database interaction – Can find solutions that effectively address persistence challenges and let them focus on J2EE application

Next Steps….  Recommended demos and/or hands-on labs – TopLink Demo – Visit the Oracle Booth!  Relevant web sites to visit for more information –

otn.oracle.com Join Over 3,000,000 Developers! Free Software Downloads Free Technical Advice

 Develop your career with Oracle’s experts – Web services, Forms Upgrade to the Web, TopLink, Business Intelligence, Integration, J2EE, Linux  Connect with your peers  Sign up at FREE

Reminder – please complete the OracleWorld session survey Session Id : Thank you.

A Q & Q U E S T I O N S A N S W E R S