Topic : Hibernate 3:Advanced ORM Kaster Nurmukan.

Slides:



Advertisements
Similar presentations
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Advertisements

ISP 121 Access Normalization and Relationships. Normalization Say we’re operating a pet day-care and we need to keep information on our pets/customers.
Databases Revision.
Mapping the ER Model to Relations(1)1 Overview  Mapping entity types  Mapping relationship types  One-to-one  One-to-many  Many-to-many.
Database Design Chapter 2. Goal of all Information Systems  To add value –Reduce costs –Increase sales or revenue –Provide a competitive advantage.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
MS Access 2007 IT User Services - University of Delaware.
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
Database Relationships Objective 5.01 Understand database tables used in business.
Java Persistence API Maciej Adamiak. Agenda -Entity, -Entity Operations, -Query Language.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
JPA Java Persistence API. Introduction The Java Persistence API provides an object/relational mapping facility for managing relational data in Java applications.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
Geodatabase Relationships & Relationship Classes GIS 458 Spring 2006 Larry Clamp.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
Optimize Your Object Model Paul Dayan – Sales Engineer.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Topic : JPA Kaster Nurmukan. Overview of JPA EntityManager.
OK lets start, who am I ?. Nayden Gochev (a.k.a. JOKe) Java Spring Android Hybris GWT EJB JSF RMI JAX-RS Struts JMS JPA Hibernate C# ASP.NET TestStudio.
EJB 3.0 Persistence Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
1 Database & DBMS The data that goes into transaction processing systems (TPS), also goes to a database to be stored and processed later by decision support.
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Access Review. Access Access is a database application A database is a collection of records and files organized for a particular purpose Access supports.
1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
Middleware Technology (J2EE/EJB) Entity Bean (JBoss EJB 3.0 tutorial)
ENTITY RELATIONSHIP DIAGRAM ENTITY RELATIONSHIP DIAGRAM IS A SPECIALIZED GRAPHIC THAT ILLUSTRATES THE INTERRELATIONSHIPS BETWEEN ENTITIES IN A DATABASE.
Enterprise Java v041109Container Managed Relationships1 Container Managed Relationships (CMR) Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
The Java Persistence API ©SoftMoore ConsultingSlide 1.
Java Persistence API part 1 INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Java Persistence API (JPA) Relationships. Kinds of relationships UML associations and aggregations (ER non- identifying relationships, shared semantics)
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Chapter 14 Semantic Modeling. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.14-2 Topics in this Chapter The Overall Approach The E/R Model.
1 6 Concepts of Database Management, 5 th Edition, Pratt & Adamski Chapter 6 Database Design 2: Design Methodology Spring 2006.
Database Relationships Objective 5.01 Understand database tables used in business.
JPA in Vaadin CSCI 3130 Winter What is JPA?  Java Persistence API  Allows for “easy” storage of Java Objects  Is a type of Object Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Chapter 2: Entity-Relationship Model. 3.2 Chapter 2: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Entity-Relationship.
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
Data Modeling AND ER MODELS.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA 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.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
DATA SCIENCE MIS0855 | Spring 2016 Designing Data
Hibernate Annotation 李日貴 (jini) jakarta99 AT gmail.com SoftLeader Tech. Corp. Taiwan Java Annotation Lesson 1.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
SchemaLogic Workshop Tools for Enterprise Metadata Management and Synchronization Prepared for the University of Washington Information School Applied.
Object-Relational Mapping. Contents  Default Mapping Rules  Elementary Mapping  Embeddables  Relationship Mapping  Inheritance Mapping.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA Chengyu Sun California State University, Los Angeles.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Advanced Java Programming
Database Applications (15-415) ORM - Part I Lecture 11, February 11, 2018 Mohammad Hammoud.
JPA: Mapping to an existing database
CS3220 Web and Internet Programming SQL and MySQL
Chengyu Sun California State University, Los Angeles
Chapter 4 Introduction to MySQL.
CS3220 Web and Internet Programming SQL and MySQL
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Topic : Hibernate 3:Advanced ORM Kaster Nurmukan

O/R Mapping Primary entity annotations EntityManager Entity Relationships Practice

Class-level annotations Id field Fields of simple types (can be omitted) Fields of class types

Embedded class Collections Inheritance

public class Address { String street; String city; String state; String zip; } users id…streetcitystatezip… public class User { Integer id; String username String password; Address address; }

@Embeddable public class Address { String street; String city; String state; String zip; public class User Integer id; String username String Address address; }

public class Customer { Integer id; String name; String address; Set phones; }

id customersCustomer_phones Set phones;

name = “customer_phones”, = “customer_id”) Set phones;

Order by property ASC|DESC”) –Simple types do not have properties Order by a = “phone_order”) List phones;

Relationships (a.k.a. associations) –one-to-many –many-to-many Unidirectional vs. Bidirectional Set and List Cascading behaviors

Many-to-Many Many-to-One / One-to-Many One-to-One

Many-to-Many Relationship Each entity in E 1 can be related to many entities in E 2 Each entity in E 2 can be related to many entities in E 1 E1E1 E2E2

Many-to-One Relationship Each entity in E 1 can be related to one entities in E 2 Each entity in E 2 can be related to many entities in E 1 E1E1 E2E2

One-to-One Relationship Each entity in E 1 can be related to one entities in E 2 Each entity in E 2 can be related to one entities in E 1 E1E1 E2E2

Books and authors?? Books and editors??

A customer may own multiple accounts An account only has one owner

public class Account { Integer id; Double balance; Date createdOn; Customer owner; } public class Customer { Integer id; String name; String address; Set phones; Set accounts; }

public class Account { Integer id; Double balance; Date createdOn; } public class Customer { Integer id; String name; String address; Set phones; Set accounts; }

public class Account { Integer id; Double balance; Date createdOn; Customer owner; } public class Customer { Integer id; String name; String address; Set phones; }

Do the three OO designs result in different database schemas?? Does it make any difference on the application side?? Which one should we use??

public class Account { Integer id; Double balance; Date Customer owner; } public class Customer { Integer id; String name; String address; Set Set accounts; } property

public class Customer { Integer id; String name; String address; “createdOn asc” ) List accounts; }

A customer may own multiple accounts An account may have multiple owners

public class Account { Integer id; Double balance; Date Set owners; } public class Customer { Integer id; String name; String address; Set Set accounts; }

name = “account_owners”, = “account_id”), ) Set owners;

Whether an operation on the parent object (e.g. Customer) should be applied to the children objects in a collection (e.g. List ) Customer c = new Customer(“cysun”); Account a1 = new Account(); Account a2 = new Account(); c.getAccounts().add( a1 ); c.getAccounts().add( a2 ); entityManager.persist(c); // will a1 and a2 be saved as well? entityManager.remove(c); // will a1 and a2 be deleted from db??

api/javax/persistence/CascadeType.htmlhttp://sun.calstatela.edu/~cysun/documentation/jpa-2.0- api/javax/persistence/CascadeType.html

@OneToMany(mappedBy=“owner”, cascade=CascadeType.PERSIST) List cascade={CascadeType.PERSIST, CascadeType.MERGE}) List cascade=CascadeType.ALL) List accounts;

public class CDAccount extends Account { Integer term; }

idaccount_typebalancecreated_onterm accounts Discriminator column

@DiscrimnatorValue(“CHECKING”) public class Account { public class CDAccount { … }

idbalancecreated_on accounts account_idterm cd_accounts foreign key

@Entity public class Account { public class CDAccount { … }

idbalancecreated_on accounts idbalancecreated_onterm cd_accounts

@Entity public class Account { public class CDAccount { … }

Understand relational design –Know what the database schema should looks like before doing the mapping Understand OO design –Make sure the application design is object-oriented

TopLink JPA Annotation Reference – annotations html annotations html Pro JPA 2 by Mike Keith and Merrick Schincariol