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.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
Maven for building Java applications By Nalin De Zoysa
1 Lecture 17 George Koutsogiannakis/SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
JPA Java Persistence API. Introduction The Java Persistence API provides an object/relational mapping facility for managing relational data in Java applications.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
IS-907 Java EE JPA: Simple Object-Relational Mapping.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Introduction to MySQL Lab no. 10 Advance Database Management System.
CSC 2720 Building Web Applications Database and SQL.
Optimize Your Object Model Paul Dayan – Sales Engineer.
CS 157B: Database Management Systems II February 4 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Topic : Hibernate 3:Advanced ORM Kaster Nurmukan.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
1 Active Records. 2 What’s Active Records? O-R Mapping layer To make database access almost a non-issue Relies heavily on convention over configuration.
Enterprise Java v041109Container Managed Relationships1 Container Managed Relationships (CMR) Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
The Java Persistence API ©SoftMoore ConsultingSlide 1.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Java Persistence API (JPA) Relationships. Kinds of relationships UML associations and aggregations (ER non- identifying relationships, shared semantics)
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Hibernate Thuy, Le Huu. Pentalog VN. Agenda Hibernate Annotations Improving performance – Lazy loading – Fetching Strategies – Dynamic insert, dynamic.
Hibernates - Many to One Association. May 12, 2011 What is Association? Association is the relation between two objects. One class holds a reference of.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA Chengyu Sun California State University, Los Angeles.
CHAPTER 9 File Storage Shared Preferences SQLite.
Hibernate Annotation 李日貴 (jini) jakarta99 AT gmail.com SoftLeader Tech. Corp. Taiwan Java Annotation Lesson 1.
Object-Relational Mapping. Contents  Default Mapping Rules  Elementary Mapping  Embeddables  Relationship Mapping  Inheritance Mapping.
OpenAccess ORM Advanced Topics Kevin Babcock April 9, 2009.
CS6320 – Java Persistence API
Logical DB Design: ER to Relational
Java Persistence: Object Inheritance Mapping
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
Lecture 6 Data Model Design (continued)
Chengyu Sun California State University, Los Angeles
Hibernate (JPA) Code First Entity Relations
SQL Server 2016 JSON Support FOR Data Warehousing
Database Applications (15-415) ORM - Part I Lecture 11, February 11, 2018 Mohammad Hammoud.
JDBC – Java Database Connectivity
Introduction To Structured Query Language (SQL)
JPA: Mapping to an existing database
Introduction To Structured Query Language (SQL)
Creating Tables Create a new table by defining the column structure.
Chengyu Sun California State University, Los Angeles
MySQL Database System Installation Overview SQL summary
Database Instructor: Bei Kang.
JDBC II IS
Presentation transcript:

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 JustMock WCF JAX-WS EntityFramework RichFaces RadControls DataAccess MVC MbUnit WebForms JustCode Eclipse PHP JavaScript Objective-C ExtJS KendoUI jQuery UI jQuery TFS Spring MVC AngularJS

JPA Advanced Topics

Data Types and Converters String (char, char[]) VARCHAR (CHAR, VARCHAR2, CLOB, TEXT) Number (BigDecimal, BigInteger, Integer, Double, Long, Float, Short, Byte) NUMERIC (NUMBER, INT, LONG, FLOAT, DOUBLE) int, long, float, double, short, byte NUMERIC (NUMBER, INT, LONG, FLOAT, DOUBLE) byte[] VARBINARY (BINARY, BLOB) boolean (Boolean) BOOLEAN (BIT, SMALLINT, INT, NUMBER) java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp, java.util.Calendar TIMESTAMP (DATE, DATETIME) java.lang.Enum NUMERIC (VARCHAR, CHAR) java.util.Serializable VARBINARY (BINARY, BLOB)

Relationships Supported Relations in JPA are : OneToOne: In this relationship each entity has exactly one reference to the other entity and vice versa. OneToMany / ManyToOne: In this relationship one entity can have multiple child entities and each child entity belongs to one parent entity. ManyToMany: In this relationship multiple entites of one type can have multiple references to entities from the other type. Embedded: In this relationship the other entity is stored in the same table as the parent entity (i.e. we have two entites for one table). ElementCollection: This relationship is similar to the OneToMany relation but in contrast to it the referenced entity is an Embedded entity. This allows to define OneToMany relationships to simple objects that are stored in contrast to the “normal” Embedded relationship in another table.

OneToOne = "T_ID_CARD") public class IdCard { private Long public Long getId() { return id; } = "T_PERSON") public class Person {... private = "ID_CARD_ID") public IdCard getIdCard() { return idCard; }

= FetchType.EAGER) The value FetchType.EAGER is the default value and specifies that each time we load a person we also want to load the ID card. On the other hand we can specify that we only want to load the ID when we actually access it by calling = FetchType.LAZY)

OneToMany = "T_PHONE") public class Phone { private Long id; private Person public Long getId() { return id; = = "PERSON_ID") public Person getPerson() { return person; } = "T_PERSON") public class Person { private List phones = new = "person", fetch = FetchType.LAZY) public List getPhones() { return phones; }

ManyToMany = "T_PROJECT") public class Project { private Long id; private String title; private List geeks = new ArrayList (); public List getGeeks() { return geeks; } = "T_GEEK") public class Geek { … private List projects = name="T_GEEK_PROJECT", _ID", referencedColumnName="ID")}, ="PROJECT_ID", referencedColumnName="ID")}) public List getProjects() { return projects; }

Embedded / public class Period { private Date startDate; private Date ="START_DATE") public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; ="END_DATE") public Date getEndDate() { return endDate; } public void setEndDate(Date endDate) { this.endDate = endDate; }

Then to Use It private Period public Period getProjectPeriod() { return projectPeriod; } public void setProjectPeriod(Period projectPeriod) { this.projectPeriod = projectPeriod; }

@Embeddable Entities in One-to-Many Relations private List billingPeriods = new name="T_BILLING_PERIOD", ) public List getBillingPeriods() { return billingPeriods; } public void setBillingPeriods(List billingPeriods) { this.billingPeriods = billingPeriods; }

Inheritance SINGLE_TABLE This strategy maps all classes to one single table. It uses a DiscriminatorColumn. JOINED - separate table. Join is used when fetching entities which can be slower. TABLE_PER_CLASS - separate table but doesn't use JOIN, instead both (or more) tables contain all the information entity needs.

Single = "T_GEEK") public class Geek extends Person { private String favouriteProgrammingLanguage; private List projects = new ArrayList = "FAV_PROG_LANG") public String getFavouriteProgrammingLanguage() { return favouriteProgrammingLanguage; } public void setFavouriteProgrammingLanguage(String favouriteProgrammingLanguage) { this.favouriteProgrammingLanguage = favouriteProgrammingLanguage; }... } //In the database you will notice new column DTYPE sql> select * from t_person; DTYPE | ID | FIRST_NAME | LAST_NAME | FAV_PROG_LANG Person | 1 | Homer | Simpson | null Geek | 2 | Gavin | Coffee | Java Geek | 3 | Thomas | Micro | C# Geek | 4 | Christian | Cup | Java

@DiscriminatorColumn(name="PERSON_TYPE", discriminatorType = public class Person { … } //then same query will show this result: sql> select * from t_person; PERSON_TYPE | ID | FIRST_NAME | LAST_NAME | FAV_PROG_LANG | 1 | Homer | Simpson | null | 2 | Gavin | Coffee | Java | 3 | Thomas | Micro | C# | 4 | Christian | Cup | Java

Single inheritance ISSUES No class discriminator column (if you have OLD legacy database.. which doesn't have discriminator column.. then you need to use crazy stuff like DescriptorCustomizer(EclipseLink) DiscriminatorFormula (Hibernate) Non nullable attributes

JOINED = public class Person { … } //then same query will show this result: sql> select * from t_person; ID | FIRST_NAME | LAST_NAME 1 | Homer | Simpson 2 | Gavin | Coffee 3 | Thomas | Micro 4 | Christian | Cup (4 rows, 12 ms) sql> select * from t_geek; FAV_PROG_LANG | ID Java | 2 C# | 3 Java | 4 (3 rows, 7 ms)

JOINED inheritance ISSUES Poor query performance Do not have/want a table for every subclass

TABLE_PER_CLASS public abstract class Project private long public class LargeProject extends Project { private BigDecimal public class SmallProject extends Project { }

TABLE_PER_CLASS inheritance ISSUES Poor query performance - The main disadvantage to the table per class model is queries or relationships to the root or branch classes become expensive. Issues with ordering and joins Because table per class inheritance requires multiple queries, or unions, you cannot join to, fetch join, or traverse them in queries. Also when ordering is used the results will be ordered by class, then by the ordering.

Mapped Superclass Mapped superclass inheritance allows inheritance to be used in the object model, when it does not exist in the data model. It is similar to table per class inheritance, but does not allow querying, persisting, or relationships to the superclass. Its main purpose is to allow mappings information to be inherited by its subclasses. The subclasses are responsible for defining the table, id and other information, and can modify any of the inherited mappings

public abstract class Project private long private String @AttributeOverride(name="name", public class LargeProject extends Project { private BigDecimal public class SmallProject extends Project { }

Mapped Superclass Issues Cannot query, persist, or have relationships. You also cannot have a relationship to a mapped superclass

Criteria API CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(Person.class); Root personRoot = query.from(Person.class); query.where(builder.equal(personRoot.get("firstName"), "Homer")); List resultList = entityManager.createQuery(query).getResultList(); //or we can write query.where(builder.and( builder.equal(personRoot.get("firstName"), "Homer"), builder.equal(personRoot.get("lastName"), "Simpson"))); In general CriteriaQuery defines the following clauses and options: distinct(), from(), select(), multiselect(), where(), orderBy(), groupBy(), having(), subquery()

Contacts Blog : Facebook: Linkedin: Skype: joke.gochev GitHub :