A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.

Slides:



Advertisements
Similar presentations
V 6, Mats Strandberg ORM With Hibernate.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
NHibernate Object/Relational Persistence for.NET.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Hibernate 1. Introduction ORM goal: Take advantage of the things SQL databases do well, without leaving the Java language of objects and classes. ORM.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
An Introduction to Hibernate Matt Secoske
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Object Persistence and Object-Relational Mapping James Brucker.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Fresher Technology Specific - JAVA Stream Hibernate Framework
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
UPortal Developers MIT August 2004 Persistence Strategy for uPortal 3 Mike DeSimone the r-smart group
Agenda What is Hibernate Spring Integration Questions Overview
Maven for building Java applications By Nalin De Zoysa
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CS 157B: Database Management Systems II January 30 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by Gavin King A lightweight framework for Java EE 5.0.
Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.
Object/Relational Mapping with Hibernate Practical ORM.
Argonne National Laboratory is managed by The University of Chicago for the U.S. Department of Energy IRMIS Out of the Box.
CS 160: Software Engineering November 5 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 157B: Database Management Systems II February 4 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Object Persistence (Data Base) Design Chapter 13.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Slide 1 Object Persistence Design Chapter 13 Alan Dennis, Barbara Wixom, and David Tegarden John Wiley & Sons, Inc. Slides by Fred Niederman Edited by.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
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.
Topic : Hibernate 2: Object Persistence and ORM Kaster Nurmukan.
Hibernate Introduction - 1 Present by Eric Yu. BeanSoft | 2 Content Understanding object/relational persistence Introduction Architecture The core interfaces.
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.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Hibernate Thuy, Le Huu Pentalog HAN. What is Hibernate? Hibernate is a free, open source Java package that makes it easy to work with relational databases.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Hibernate Basics. Basics What is persistence? Persistence in Object Oriented Applications? Paradigm Mismatch.  The Problem of Granularity.  The Problem.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Programmation des Applications Internet Internet Application Programming © - Last update: Friday, 05 February
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Hibernate Thuy, Le Huu. Pentalog VN. Agenda Hibernate Annotations Improving performance – Lazy loading – Fetching Strategies – Dynamic insert, dynamic.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
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.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Hibernate Annotation 李日貴 (jini) jakarta99 AT gmail.com SoftLeader Tech. Corp. Taiwan Java Annotation Lesson 1.
Современные технологии баз данных Лекция 7. Объектно-реляционное отображение (ORM) Технология отображения объектов какого- либо объектно-ориентированного.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
New Technology: Why, What ,How
Relational Database Collaboration
Object/Relational Mapping with Hibernate
Java Data Persistence Using Hibernate
Hibernate Bayu Priyambadha, S.Kom.
Chengyu Sun California State University, Los Angeles
SPL – PS13 Persistence Layer.
Presentation transcript:

A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department of Energy IRMIS rdbCore Java API Object-Relational Modelling (ORM)

Pioneering Science and Technology Office of Science U.S. Department of Energy 2 IRMIS rdbCore Java API What is rdbCore? -Database schema definition (ddl) - Static for now, but possible to generate for multiple db -Process variable crawler -Java database access layer (also PHP) Source code tree overview irmis/ apps/ -> pv viewer, component viewer/editor, etc. rdbCore/ -> rdbCore.jar ddl/ crawler/perl/ db/ php/ java/ gov/anl/aps/irmis/persistence/pv

Pioneering Science and Technology Office of Science U.S. Department of Energy 3 IRMIS rdbCore Java API Object-Relational Mapping (ORM) -Bridges gap between relational data model and object-oriented data model of applications -This “gap” responsible for a significant amount of development and maintenance hours -ORM allows focus on application and data, not transforming between the two models Java ORM Hibernate (Gavin King) -LGPL license -Development began in Joined jboss.org in 2003, so commercial support and training available -Very popular, mature, with active support forums -Excellent book “Hibernate in Action” ( Bauer, King)

Pioneering Science and Technology Office of Science U.S. Department of Energy 4 IRMIS rdbCore Java API Data Objects -IOCRecord -IOCBootRecordType -IOCResourceField -URIFieldType Data Access Objects -IOCBootDAO - IOCBoot findByIocName(String iocName) - List findCurrentLoads() -RecordDAO - setRecordTypeConstraint(List recTypes) - setRecordNameGlobConstraint(String recNamePattern) - List findByConstraints()

Pioneering Science and Technology Office of Science U.S. Department of Energy 5 IRMIS rdbCore Java API Code example // retrieve set of current ioc boot instances, and all their process variables IOCBootDAO ibDAO = new IOCBootDAO(); List bootList = null; Try { bootList = ibDAO.findCurrentLoads(); } catch (DAOException de) { // handle exception } // iterate over the results Iterator bootIt = bootList.iterator(); while (bootIt.hasNext()) { IOCBoot iocBoot = (IOCBoot)bootIt.next(); String iocName = iocBoot.getIoc().getIocName(); List resources = iocBoot.getIocResources(); // eager fetch, so data already here List records = iocBoot.getRecords(); // lazy, so addtl. query issued here }

Pioneering Science and Technology Office of Science U.S. Department of Energy 6 IRMIS rdbCore Java API How is this done with Hibernate? -Design the object model and relational schema (what order?) - Depends on whether rdbms schema came first or not - APS designed rdbms schema with application in mind, so our object model entities are almost 1-to-1 with relational entities (hibernate still a big plus). - Hibernate can auto-generate class source code and/or ddl if desired - APS manually created classes and ddl (for now)

Pioneering Science and Technology Office of Science U.S. Department of Energy 7 IRMIS rdbCore Java API Hibernate revolves around Session class Session session = sessionFactory.openSession() hibernate.cfg.xml IOCBoot.hbm.xml Field.hbm.xml Record.hbm.xml hibernate.cfg.xml

Pioneering Science and Technology Office of Science U.S. Department of Energy 8 IRMIS rdbCore Java API Partial Record.hbm.xml mapping <class name=“gov.anl.aps.irmis.persistence.pv.Record” table=“rec” lazy=“true” > <many-to-one name=“recordType” column=“rec_type_id” class=“gov.anl.aps.irmis.persistence.pv.RecordType” />

Pioneering Science and Technology Office of Science U.S. Department of Energy 9 IRMIS rdbCore Java API Record class (Record.java) Public class Record implements Serializable { private Long id; private String recordName; private Set fields = new HashSet(); private RecordType recordType; // constructor and accessor methods public Record() {} public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public Set getFields() { return this.fields; } public void setFields(Set fields) { this.fields = fields; } public void addField(Field field) { field.setRecord(this); fields.add(field); } public boolean equals (Object o) { if (this == other) return true; if (!(other instanceof Record)) return false; final Record castO = (Record)o; return this.getIocBoot().getId()==castO.getIocBoot().getId() && this.getRecordName() ==castO.getRecordName(); } public int hashCode() { int result = HashCodeUtil.SEED; result = HashCodeUtil.hash(result, getIocBoot().getId()); result = HashCodeUtil.hash(result, getRecordName()); return result; }

Pioneering Science and Technology Office of Science U.S. Department of Energy 10 IRMIS rdbCore Java API Querying for objects using HQL (Hibernate Query Language) -What is HQL? - minimal OO extension to SQL select -Why? - Query in terms of objects you are interested in - Db independence since Hibernate generates SQL for your db - Optimization - hibernate generally makes optimal SQL List records = session.find(“select from Record r where r.recordName like ‘ABC%’”); List records = session.find(“from Record r join fetch r.fields”); IOCBoot boot = session.find(“from IOCBoot ib where ib.ioc.iocName = ‘iocpar01’”); - OR - if you absolutely have to use native SQL and JDBC Connection con = session.connection(); // any JDBC stuff can be done here

Pioneering Science and Technology Office of Science U.S. Department of Energy 11 IRMIS rdbCore Java API Saving or updating new objects Record rec = new Record(); rec.setRecordName(“AB:CD:ai”); // set remaining fields except id Transaction tx = session.beginTransaction(); session.saveOrUpdate(rec); tx.commit();

Pioneering Science and Technology Office of Science U.S. Department of Energy 12 IRMIS rdbCore Java API Hibernate experience -It has a learning curve (2 weeks ?) -Very active support forums where core developers lurk and answer questions within hours -Extremely flexible - Only a small corner of mapping possibilities shown - Will work with schemas using natural keys - Objects can be mapped to one or many tables, either through composition or association - Easy to tweak mappings and watch behavior of SQL (comparing query time using lazy versus eager fetch) -Good log output (uses commons-logging and log4j)