The Object-Oriented Paradigm. Employee Application Object. The Reality of DBMS. Employee Database Table. From Database to Application.

Similar documents
HIBERNATE MOCK TEST HIBERNATE MOCK TEST IV

Kyle Brown Knowledge Systems Corporation by Kyle Brown and Knowledge Systems Corporation

Hibernate Interview Questions

Generating A Hibernate Mapping File And Java Classes From The Sql Schema

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. SQL Programming. Lecture 8. SQL Programming

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

Hibernate Overview. By Khader Shaik

HIBERNATE MOCK TEST HIBERNATE MOCK TEST I

Database Application Architectures

Systems Analysis and Design in a Changing World, Fourth Edition. Chapter 12: Designing Databases

Introduction to Databases [p.3]

International Journal of Advance Research in Engineering, Science & Technology HIBERNATE FRAMEWORK FOR ENTERPRISE APPLICATION

JAVA AND DATABASES. Summer 2018

object/relational persistence What is persistence? 5

Chapter 3. Harnessing Hibernate

JDBC Programming: Intro

Questions and Answers. A. A DataSource is the basic service for managing a set of JDBC drivers.

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

Working with Databases and Java

COMP9321 Web Application Engineering

CSE 308. Database Issues. Goals. Separate the application code from the database

Lightweight J2EE Framework

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Hibernate in close action. INF5750/ Lecture 3 (Part III)

Chapter 2. Introduction to Mapping

What data persistence means? We manipulate data (represented as object state) that need to be stored

Unit 6 Hibernate. List the advantages of hibernate over JDBC

Object Persistence and Object-Relational Mapping. James Brucker

Java Object/Relational Persistence with Hibernate. David Lucek 11 Jan 2005

COMP 430 Intro. to Database Systems. SQL from application code

JDO XML MetaData Reference (v5.2)

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

JDBC BASIC 19/05/2012. Objectives. Java Database Connectivity. Definitions of JDBC. Part 1. JDBC basic Working with JDBC Adv anced JDBC programming

Object-relational mapping EJB and Hibernate

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Package sjdbc. R topics documented: December 16, 2016

Web Application Development Using Spring, Hibernate and JPA

Step By Step Guideline for Building & Running HelloWorld Hibernate Application

Java Persistence API (JPA)

BUSINESS INTELLIGENCE LABORATORY. Data Access: Relational Data Bases. Business Informatics Degree

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

Web Application Development Using Spring, Hibernate and JPA

Web Application Development Using Spring, Hibernate and JPA

ADVANCED JAVA TRAINING IN BANGALORE

Programming in Java

Table of Contents - Fast Track to Hibernate 3

CS317 File and Database Systems

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

COMP9321 Web Application Engineering

Introduction. Example Databases

O/RM - Introduction. Christian Horsdal Gammelgaard

Architecture overview

This tutorial is going to guide you throughout the setup of your. workspace. First, we re going to see how to install the MySQL RDBMS

Advances in Programming Languages

Several major software companies including IBM, Informix, Microsoft, Oracle, and Sybase have all released object-relational versions of their

JDBC. Oracle ODBC SP API SP API. SQL server C function calls. SQL server ODBC SP API. Oracle DSN Oracle ODBC Oracle

ThingWorx Relational Databases Connectors Extension User Guide

Porting a Web Application to Hibernate Environment

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

Lecture 9&10 JDBC. Mechanism. Some Warnings. Notes. Style. Introductory Databases SSC Introduction to DataBases 1.

The dialog boxes Import Database Schema, Import Hibernate Mappings and Import Entity EJBs are used to create annotated Java classes and persistence.

Setting Schema Name For Native Queries In. Hibernate >>>CLICK HERE<<<

Lecture 2. Introduction to JDBC

Embedded SQL. Host Language (record-oriented) 3. Process a tuple at a time. 1. Query. 4. Close Cursor

Introduction to Relational Database Management Systems

Erik Dörnenburg JAOO 2003

PersistF: A Transparent Persistence Framework with Architecture Applying Design Patterns

SDN Community Contribution

POJOs to the rescue. Easier and faster development with POJOs and lightweight frameworks

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

PERSİSTENCE OBJECT RELATİON MAPPİNG

Hibernate. Recipes. A Problem-Solution Approach. Srinivas Guruzu and Gary Mak. Hibernate 3.5 THE EXPERT S VOICE OPEN SOURCE.

Overview. ❶ Short introduction to the company. ❶ Short history of database and DBMS. ❶ What is the next DBMS s generation? ❶ Introduction to Tamino

Voyager Database Developer s Guide Version 1.0 for Voyager 8.0

CGS 3066: Spring 2017 SQL Reference

Remote Health Service System based on Struts2 and Hibernate

Advances in Programming Languages

Introduction. Who wants to study databases?

CS 146 Database Systems

Transparent Java access to mediated database objects

DATABASE DESIGN I - 1DL300

Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200

The Design of JDBC The Structured Query Language Basic JDBC Programming Concepts Query Execution Scrollable and Updatable Result Sets

Chapter 3 DB-Gateways

Page 1

Table of Contents. I. Pre-Requisites A. Audience B. Pre-Requisites. II. Introduction A. The Problem B. Overview C. History

Index. setmaxresults() method, 169 sorting, 170 SQL DISTINCT query, 171 uniqueresult() method, 169

Database Explorer Quickstart

Database Access. Rick Cattell JavaSoft

Struts: Struts 1.x. Introduction. Enterprise Application

Installing MySQL. Hibernate: Setup, Use, and Mapping file. Setup Hibernate in IDE. Starting WAMP server. phpmyadmin web console

Database Management Systems. Chapter 3 Part 2

Chapter 3 DB-Gateways

Introduction to Data Management. Lecture #2 (Big Picture, Cont.)

HIBERNATE - ONE-TO-ONE MAPPINGS

Web Application Development Using JEE, Enterprise JavaBeans and JPA

HIBERNATE - INTERCEPTORS

Mappings and Queries. with. Hibernate

Transcription:

The Object-Oriented Paradigm CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles The world consists of objects So we use object-oriented languages to write applications We want to store some of the application objects (a.k.a. persistent objects), e.g. accounts, customers, employees So we use a Object Database? The Reality of DBMS Relational DBMS are still predominant n Best performance n Most reliable n Widest support Bridge between OO applications and relational databases n CLI and embedded SQL n Object-Relational Mapping (ORM) tools Employee Application Object public class Employee Integer id; String name; Employee supervisor; Employee Database Table From Database to Application create table employees ( id integer primary key, name varchar(255), supervisor integer references employees(id) ); So how do we construct an Employee object based on the data from the database? public class Employee Integer String Employee id; name; supervisor; public Employee( Integer id ) // access database to get name and supervisor 1

Problems with CLI and Embedded SQL SQL statements are hard-coded in applications public Employee( Integer id ) PreparedStatment p; p = connection.preparestatment( select * from employees where id =? ); Problems with CLI and Embedded SQL Tedious translation between application objects and database tables public Employee( Integer id ) ResultSet rs = p.executequery(); if( rs.next() ) name = rs.getstring( name ); Problems with CLI and Embedded SQL The ORM Approach Application design has to work around the limitations of relational DBMS public Employee( Integer id ) ResultSet rs = p.executequery(); if( rs.next() ) supervisor =?? Application ORM tool Persistent Data Store customer employee account Oracle, MySQL, SQL Server Flat files, XML Advantages of ORM Common ORM Tools Make RDBMS look like ODBMS Data are accessed as objects, not rows and columns Simplify many common operations. E.g. System.out.println(e.supervisor.name) Improve portability n Use an object-oriented query language (OQL) n Separate DB specific SQL statements from application code Caching Java Data Object (JDO) n One of the Java specifications n Flexible persistence options: RDBMS, OODBMS, files etc. Hibernate n Most popular Java ORM tool right now n Persistence by RDBMS only Others n http://en.wikipedia.org/wiki/object-relational_mapping n http://www.theserverside.net/news/thread.tss?thread_id=29 914 2

Hibernate Application Architecture Setup Hibernate hibernate Download hibernate core from http://www.hibernate.org Add the following jar files to CLASSPATH n hibernate-3.0\hibernate3.jar n All the jar files under hibernate-3.0\lib n The JDBC driver of your DBMS A Sample Hibernate Application Java classes n Employee.java Code to access the persistent objects n EmployeeTest.java O/R Mapping files n Employee.hbm.xml Hibernate configuration file n hibernate.cfg.xml (Optional) Logging configuration files n Log4j.properties Java Classes Plain Java classes (POJOs) except that n There must be an identity field n Each persistent field must has a pair of getter and setter The identity field is used to uniquely identify an object The getter and setter for a property xxx follows the naming convention: n getxxx() n setxxx() O/R Mapping Files Hibernate Configuration Files Describe how class fields are mapped to table columns Three important types of elements in a a mapping file n <id> n <property> - when the field is of simple type n Association when the field is of a class type w <one-to-one> w <many-to-one> w <many-to-many> Tell hibernate about the DBMS and other configuration parameters Either hibernate.properties or hibernate.cfg.xml or both n Sample files under hibernate-3.0/etc 3

Log4j Configuration File Log4j is a logging tool for Java Log levels n DEBUG, INFO, WARN, ERROR, FATAL Log output (appender) n File n Stdout Access Persistent Objects SessionFactory Configuration Session Query Transaction Retrieve Objects Update Objects Hibernate Query Language (HQL) A query language that looks like SQL, but for accessing objects Automatically translated to DB-specific SQL statements select e from Employee e where e.id = :id n From all the Employee objects, find the one whose id matches the given value Hibernate Query Language (HQL) select e from Employee e where e.id = :id A query language that looks like SQL, but deals with objects instead of tables n E.g. from all the Employee objects, find the one whose id matches the given value n OO language-like syntax, for example e.supervisor.name Support named query parameters Automatically translated into DB-specific SQL statement hbm2ddl Generate DDL statements from Java classes and mapping files See hbm2ddl.bat in the sample code More About Mapping Map collections Map subclasses n Table per concrete class n Table per class hierarchy n Table per subclass 4

O/R Mapping vs. ER-Relational Conversion More Hibernate Resource O/R Mapping Class <property> Association Subclass table per concrete class table per class hierarchy table per subclass ER-Relational Conversion Entity Set Attribute Relationship Subclass OO method NULL method ER method Hibernate in Action by Christian Bauer and Gavin King Hibernate documentation at http://www.hibernate.org 5