ODBC and JDBC O/R Mapping David Rabinowitz. June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Distributed Application Development B. Ramamurthy.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
CSE 190: Internet E-Commerce Lecture 13: Database code.
ODBC and JDBC O/R Mapping Amit Shabtay. June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
An Introduction to Hibernate Matt Secoske
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
CSCI 6962: Server-side Design and Programming
Agenda What is Hibernate Spring Integration Questions Overview
Interacting With Data Databases.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Programming in Java Corresponds with Chapter 32, 33.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Midterm Exam Chapters 1,2,3,5, 6,7 (closed book) March 11, 2014.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Creating and using Persistent Data From before – Where does the data come from? – Why is it kept? – How is it used? Affects design and implementation choices.
Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.
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.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
Java Data Persistence Using Hibernate Jack Gardner October 2004.
Object-Relational Mapping with Hibernate Brian Sam-Bodden Principal Partner Integrallis Software, LLC. August 1 - 5, 2005.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
Data Resource Management Application Layer TPS A RCHITECTURE Data Layer Sales/MarketingHR Finance/Accounting Operations Spreadsheet Data MS Access Accounts.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Online Training. Introduction to Hibernate Hibernate is a high-performance Object-Relational persistence and query service which takes care.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
Chengyu Sun California State University, Los Angeles
Java Data Persistence Using Hibernate
Introduction to Server-Side Web Development using JSP and Databases
Hibernate Bayu Priyambadha, S.Kom.
Data Model.
Java Database Connectivity
Chapter 10 ADO.
Developing and testing enterprise Java applications
Java API for Database Connectivity
A Very Brief Introduction to Relational Databases
Data Access Layer (Con’t) (Overview)
Chengyu Sun California State University, Los Angeles
Presentation transcript:

ODBC and JDBC O/R Mapping David Rabinowitz

June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written using object oriented techniques and languages. Persistence is the key of saving data Many of today’s applications use databases Dynamic websites Management applications (ERP, CRM, etc.) Many many more… How do we easily combine the two? Or: How do we easily persist objects?

June 2nd, 2004 Object Oriented Design Course 3 A Brief Introduction To Databases (1) We want to represent pieces of data Same meta data Student – first name, last name, … Course – number, name, … We want to relate between data Which courses does a student take?

June 2nd, 2004 Object Oriented Design Course 4 A Brief Introduction To Databases (2) We define our data as entities We define their connections as relationships And then define the Entity- Relationship Diagram More on that in the databases course Very recommended!

June 2nd, 2004 Object Oriented Design Course 5 Example – The Relations Student Id FirstName LastName Course Number Name Description Course Participation Id StudentId CourseNumber Grade Table Relations (Constraints)

June 2nd, 2004 Object Oriented Design Course 6 Example – The Tables (1) IdFirstNameLastName BartSimpson LisaSimpson MilhouseVan Houten NumberNameDescription 67615oodObject Oriented Design 67506dbDatabases 67808osOperating Systems Courses Students

June 2nd, 2004 Object Oriented Design Course 7 Example – The Tables (2) IdStudentIdCourseNumberGrade How do we use all this data ?

June 2nd, 2004 Object Oriented Design Course 8 CRUD Operations (I) Create INSERT INTO Students (Id, FirstName, LastName) VALUES (55, “Maggie”, “Simpson”) Read (or Retrieve) SELECT FirstName,LastName FROM Studnets WHERE FirstName=“Maggie”

June 2nd, 2004 Object Oriented Design Course 9 CRUD Operations (II) Update UPDATE Students SET FirstName=“Mag” WHERE Id=55 Delete DELETE FROM Students WHERE FirstName=“Mag”

June 2nd, 2004 Object Oriented Design Course 10 The Objects

June 2nd, 2004 Object Oriented Design Course 11 Database Connection SQL is an embedded language Inserted as part of the code How to connect to the database? Special libraries Special network protocol General interface libraries – ODBC, JDBC, etc.

June 2nd, 2004 Object Oriented Design Course 12 ODBC Open Database Connectivity Access any data from any application No matter what the database is! Also, the data can be in Excel spreadsheets or text files. The basic idea – introduce a general database API to the application Each database has different implementation

June 2nd, 2004 Object Oriented Design Course 13 ODBC API Driver The basic hook to the system Connection Holds the connection to the database RecordSet Wraps a result of database query Command Used to send commands (insert, delete) to the database

June 2nd, 2004 Object Oriented Design Course 14 Example Set conn = new ADODB.Connection conn.Open “ ” Set rs = new ADODB.RecordSet rs.Open “SELECT * From Students”, _ conn For Each f in rs.Fields Response.Write “ ” & f.Name & _ “ ” Next

June 2nd, 2004 Object Oriented Design Course 15 Example (II) While Not rs.EOF Response.Write “ ” For Each f in rs.Fields Response.Write “ ” Response.Write rs(f.Name) Response.Write “ ” Next Response.Write “ ” rs.MoveNext Wend

June 2nd, 2004 Object Oriented Design Course 16 JDBC Java Database Connectivity From the first version of Java Was modeled on ODBC Driver, Connection and ResultSet Lack in ODBC is Statement PreparedStatment, CallableStatment Extensive use of the factory pattern

June 2nd, 2004 Object Oriented Design Course 17 CRUD Problems Has to be written and maintained for each object Tedious and error prone work Most of the code is similar Only table name and fields change

June 2nd, 2004 Object Oriented Design Course 18 O/R Mapping Tools Specifications EJB CMP (Container Managed Persistence) JDO Commercial Products TopLink Open Source Tools Hibernate OJB Many many more …

June 2nd, 2004 Object Oriented Design Course 19 Hibernate An open source project Created by Gavin King Now belongs to the JBoss group

June 2nd, 2004 Object Oriented Design Course 20 How does hibernate works? // 1. Build a Product Course c = new Course(67615, "ood", "Object Oriented Course"); // 2. Fire up Hibernate Configuration cfg = new Configuration(); cfg.addClass(Course.class); SessionFactory sf = cfg.buildSessionFactory(); // 3. Open Session Session session = sf.openSession(); // 4. Save Product and close Session Transaction tx = sess.beginTransaction(); session.save(c); tx.commit(); session.close();

June 2nd, 2004 Object Oriented Design Course 21 Behind The Curtains How does Hibernates knows how to relate the class Product to the table? XML definition file for each class Defines its mapping to the table in the database Defines its relations to other classes

June 2nd, 2004 Object Oriented Design Course 22 Course.hbm.xml <column name="name" sql-type="char(255)" not-null="true"/> <column name=" description" sql-type="char(255)" not-null="true"/>

June 2nd, 2004 Object Oriented Design Course 23 HQL - Hibernate Query Language We are working on objects, not tables SQL cannot be used HQL is similar to SQL, but works on objects

June 2nd, 2004 Object Oriented Design Course 24 HQL Example Query q = session.createQuery(“select student from student in class tir11.Student where student.name=:name”); q.setString(“name”, “maggie”); List l = q.list(); Student maggie = l.get(0);

June 2nd, 2004 Object Oriented Design Course 25 Updating & Deleting //update maggie.setName(“mag”); session.saveOrUpdate(maggie); //delete Session.delete(bart); Tx.commit();

June 2nd, 2004 Object Oriented Design Course 26 Relations How to declare the relation between Student and CourseParticipation ? Student.hbm.xml <set name="courses" inverse="true” table="CourseParticipations"> <one-to-many class= "tir11.CourseParticipation"/>

June 2nd, 2004 Object Oriented Design Course 27 And on the other side <class name="tir11.CourseParticipation" table="CourseParticipations"> <many-to-one name=“student" class=“tir11.Student" column=“StudentId" /> <many-to-one name=“course" class="tir11.Course" column=“CourseNumber"/>

June 2nd, 2004 Object Oriented Design Course 28 Example Course ood =...; Course db =...; Student bart = new Student( , “Bart”, “Simpson”); bart.addCourse(ood); bart.addCourse(db); tx.begin(); session.save(bart); tx.commit() Session.close();

June 2nd, 2004 Object Oriented Design Course 29 How can that happen? Reflection Bytecode manipulation

June 2nd, 2004 Object Oriented Design Course 30 Objects & Databases Two widely used technologies … that not always cooperate easily Direct CRUD operations are expensive to write (test!) and maintain O/R mapping tools can ease the development

June 2nd, 2004 Object Oriented Design Course 31 More information /01/14/hibernate.html Similar to the example shown in class