Hibernate Query Language Make SQL be object oriented – Classes and properties instead of tables and columns – Polymorphism – Associations – Much less verbose.

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

Relational Algebra Relational algebra consists of a set of relational operators Each operator has one or more relations as input and creates a new relation.
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Hibernate 1. Introduction ORM goal: Take advantage of the things SQL databases do well, without leaving the Java language of objects and classes. ORM.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Mary K. Olson PS Reporting Instance – Query Tool 101.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Session-01. Hibernate Framework ? Why we use Hibernate ?
An Introduction to Hibernate Matt Secoske
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Agenda What is Hibernate Spring Integration Questions Overview
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
EJB Entity Beans “Modeling your data”.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Object persistence with Hibernate in Decision Deck 1.1 Gilles Dodinet 2 nd Decision Deck Workshop 2008, February.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.
1 ICS 184: Introduction to Data Management Lecture Note 10 SQL as a Query Language (Cont.)
Object/Relational Mapping with Hibernate Practical ORM.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
Relational Databases (MS Access)
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
Chapter 4 Multiple-Table Queries
CS1100: Microsoft Access Managing Data in Relational Databases Created By Martin Schedlbauer CS11001Microsoft Access - Introduction.
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.
An Introduction to Object/Relational Persistence and Hibernate Yi Li
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
February,2006 Advanced DB System Object Relational Model Prof: Dr Rahgozar Euhanna Ghadimi, Mostafa Keikha Discussion, Implementation.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Hibernate Basics. Basics What is persistence? Persistence in Object Oriented Applications? Paradigm Mismatch.  The Problem of Granularity.  The Problem.
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
QUERY CONSTRUCTION CS1100: Data, Databases, and Queries CS1100Microsoft Access1.
Hibernate Thuy, Le Huu. Pentalog VN. Agenda Hibernate Annotations Improving performance – Lazy loading – Fetching Strategies – Dynamic insert, dynamic.
Sean Chambers.  ORM stands for Object Relational Mapper  Maps your POCO (plain old clr objects) to your relational model using XML config  Relieves.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
Interacting with LexEVS 5.0 LexEVS in a Distributed Environment November 2009.
Hibernate Basics 廖峻鋒 Sep 14,2004 NTU Dept. of CSIE.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS6320 – Java Persistence API
Chengyu Sun California State University, Los Angeles
Structured Query Language
Structured Query Language (Data Manipulation Language)
Database Systems: Design, Implementation, and Management Tenth Edition
Object/Relational Mapping with Hibernate
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
Structured Query Language (SQL) William Klingelsmith
Java Data Persistence Using Hibernate
Chapter 4 Summary Query.
Access: SQL Participation Project
M1G Introduction to Database Development
Database Systems: Design, Implementation, and Management Tenth Edition
Joins and other advanced Queries
Topic 12 Lesson 2 – Retrieving Data with Queries
Set Operations Union Intersect Minus.
Microsoft Access Date.
Presentation transcript:

Hibernate Query Language Make SQL be object oriented – Classes and properties instead of tables and columns – Polymorphism – Associations – Much less verbose than SQL Full support for relational operations – Inner/outer/full joins, cartesian products – Projection – Aggregation (max, avg) and grouping – Ordering – Subqueries – SQL function calls

Hibernate Query Language HQL is a language for talking about “sets of objects” It unifies relational operations with object models

Hibernate Query Language Simplest HQL Query: from AuctionItem i.e. get all the AuctionItems: List allAuctions = session.createQuery(“from AuctionItem”).list();

Hibernate Query Language More realistic example: select item from AuctionItem item join item.bids bid where item.description like ‘hib%’ and bid.amount > 100 i.e. get all the AuctionItem s with a Bid worth > 100 and description that begins with “hib”

Hibernate Query Language Projection: select item.description, bid.amount from AuctionItem item join item.bids bid where bid.amount > 100 order by bid.amount desc i.e. get the description and amount for all the AuctionItems with a Bid worth > 100

Hibernate Query Language Aggregation: select max(bid.amount), count(bid) from AuctionItem item left join item.bids bid group by item.type order by max(bid.amount)

Hibernate Query Language Runtime fetch strategies: from AuctionItem item left join fetch item.bids join fetch item.successfulBid where item.id = 12 AuctionItem item = session.createQuery(…).uniqueResult(); //associations already fetched item.getBids().iterator(); item.getSuccessfulBid().getAmount();

Criteria Queries List auctionItems = session.createCriteria(AuctionItem.class).setFetchMode(“bids”, FetchMode.EAGER).add( Expression.like(“description”, description) ).createCriteria(“successfulBid”).add( Expression.gt(“amount”, minAmount) ).list(); Equivalent HQL: from AuctionItem item left join fetch item.bids where item.description like :description and item.successfulbid.amount > :minAmount

Example Queries AuctionItem item = new AuctionItem(); item.setDescription(“hib”); Bid bid = new Bid(); bid.setAmount(1.0); List auctionItems = session.createCriteria(AuctionItem.class).add( Example.create(item).enableLike(MatchMode.START) ).createCriteria(“bids”).add( Example.create(bid) ).list(); Equivalent HQL: from AuctionItem item join item.bids bid where item.description like ‘hib%’ and bid.amount > 1.0

Fine-grained Persistence “More classes than tables” Fine-grained object models are good – Greater code reuse – More typesafe – Better encapsulation

Components Address class street, city, postCode properties STREET, CITY, POST_CODE columns of the PERSON and ORGANIZATION tables Mutable class

Components …

Custom Types MonetoryAmount class Used by lots of other classes Maps to XXX_AMOUNT and XXX_CURRENCY columns Performs currency conversions (behaviour!) Might be mutable or immutable

Custom Types … We still have to write the MonetoryAmountUserType class!

Detached Object Support For applications using servlets + session beans You don’t need to select a row when you only want to update it! You don’t need DTOs anymore! You may serialize objects to the web tier, then serialize them back to the EJB tier in the next request Hibernate lets you selectively reassociate a subgraph! (essential for performance)

Detached Object Support Step 1: Retrieve some objects in a session bean: public List getItems() throws … { return getSession().createQuery(“from AuctionItem item where item.type = :itemType”).setParameter(“itemType”, itemType).list(); }

Detached Object Support Step 2: Collect user input in a servlet/action: item.setDescription(newDescription);

Detached Object Support Step 3: Make the changes persistent, back in the session bean: public void updateItem(AuctionItem item) throws … { getSession().update(item); }

Hibernate Info Hibernate in Action (Manning, 2004) Tool support – – –