IS-907 Java EE Introduction to JPA. Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes,

Slides:



Advertisements
Similar presentations
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
Advertisements

.NET Database Technologies: Open-Source Frameworks.
JBoss Seam: Contextual Components Jason Bechtel
Persistent State Service 1 CORBA Component  Component model  Container programming model  Component implementation framework  Component packaging and.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Entities and Persistence. Entity Beans Topics to be Covered: Entities are POJOs Managed/Unmanaged Entities Persistence Unit EntityManager Basic Relational.
Database Management: Getting Data Together Chapter 14.
Chapter 14 Getting to First Base: Introduction to Database Concepts.
Designing a Database Unleashing the Power of Relational Database Design.
ORM Technologies and Entity Framework (EF)
Session-02.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
1 Lecture 18 George Koutsogiannakis/Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
The Java Persistence API Edel Sherratt. Contents Revisit applications programming Using Java Persistence API.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Spring Roo CS476 Aleksey Bukin Peter Lew. What is Roo? Productivity tool Allows for easy creation of Enterprise Java applications Runs alongside existing.
CIS 764 Kansas State University
Introduction to JPA Java Persistence API Introduction to JPA.
Rice KRAD Data Layer JPA Design Eric Westfall July 2013.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Towards Bboogle 3.0.0: a Technical Walkthrough Patricia Goldweic Sr. Software Engineer AR&T, Northwestern University Brian Nielsen Manager, Faculty Support.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Database Design Concepts
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Agenda What is Hibernate Spring Integration Questions Overview
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.
IS-907 Java EE JPA: Simple Object-Relational Mapping.
ORM with JPA/Hibernate overview Petar Milev. ContentsContents 1.ORM Concepts Java class to database tableJava class to database table Java object to database.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
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.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Dali JPA Tools. About Dali Dali JPA Tools is an Eclipse Web Tools Platform sub-Project Dali 1.0 is a part of WTP 2.0 Europa coordinated release Goal -
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
OVERVIEW ON HOW ENTITY FRAMEWORK CODE FIRST CAN EASE THE DEVELOPMENT PROCESS Entity Framework Code First 11/19/2013 Joe Walling Copyright Walling Info.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
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.
Topic : JPA Kaster Nurmukan. Overview of JPA EntityManager.
Enterprise Java Java Persistence: EntityManager. Enterprise Java v070903Java Persistence: EntityManager2 Goals Become familiar with the Java Persistence.
EJB 3.0 Persistence Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
1 Apache TomEE // JavaEE Web Profile on Tomcat Jonathan #TomEE.
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
MCS 270 Spring 2014 Object-Oriented Software Development.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
The Java Persistence API ©SoftMoore ConsultingSlide 1.
Java Persistence API part 1 INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
v110912Java Persistence: EntityManager2 Overview Earlier versions of EJB Specification defined the persistence layer –javax.ejb.EntityBean Java EE 5 moved.
By Srinivas Mahakud Java Persistence API JPA. Review Topics: Introduction what is the JPA? What is the JPA contains of? Why developers should Create the.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Hibernate Thuy, Le Huu. Pentalog VN. Agenda Hibernate Annotations Improving performance – Lazy loading – Fetching Strategies – Dynamic insert, dynamic.
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 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.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Don't Know Jack About Object-Relational Mapping?
Chengyu Sun California State University, Los Angeles
Java Persistence Architecture (JPA)
Step 1 Create Database Info activity in Adeptia Server specifying the driver, URL and user credentials information for the database in which stored.
A very brief introduction
Advanced Java Programming
Entity Framework By: Casey Griffin.
JPA: Mapping to an existing database
Java Programming Course
CS4961 Software Design Laboratory Understand Aquila Backend
Topics Persistence API for JAVA EE5 Java Transaction API Entity class.
Chengyu Sun California State University, Los Angeles
Presentation transcript:

IS-907 Java EE Introduction to JPA

Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes, and between table rows and objects POJO (plain old java object) based Portable Even Åby Larsen IS-102 Introduksjon2

Object-Relational-Mapping Description of how an object model “maps” to a relational data model Class to table(s) Object properties (attributes) to columns or relations The mapping can be described as java source code annotations, or in xml mapping files xml mapping files override the source code annotations IS Course Info3

Persistence Unit A named configuration of entity classes their mapping to tables in a database transaction model Defined in persistence.xml, and source code annotations, or orm.xml mapping file Represented in java by an EntityManagerFactory object Even Åby Larsen IS-102 Introduksjon4

Persistence Context a managed set of entity objects (a “session”) keeps track of changes accessed through EntityManager objects Even Åby Larsen IS-102 Introduksjon5

Transactions define when entities are synchronized with the database bound to a persistence context accessible through UserTransaction objects Even Åby Larsen IS-102 Introduksjon6

Annotations Annotations provide data about a program that is not part of the program itself. Example uses: Information for the compiler Compile-time and deployment-time processing Runtime processing You can think of annotations as a special kind of comment that is intended for the computer rather than for humans. Annotations are java interfaces, so it is necessary to import them before they can be used IS Course Info7

JPA annotations Class annotations provide information about the class Class annotations appear before the class declaration (normally just before the public public class Employee {... } Property annotations provide information about class properties. Property annotations appear before the attribute declaration (just before private), or before the get-method declaration (just before private long empNo; public long getEmpNo() {... } (but not in both places – you must consistently use one variant) IS Course Info8

JPA Entity annotations To mark a class as a persistent entity (i.e. that objects of the class can be stored in a database), use annotation: import public class Employee {... } JPA will attempt to use the classname as a table name, and the attribute names as column names IS Course Info9

JPA Id annotations annotations is used to specify the primary key. annotation can be used to specify automatic generation of the primary key values import public class private long empNo;... } IS Course Info10

Interacting with the database To interact with the database we use an instance of EntityManager The EntityManager manages a set of entities (roughly the contents of a specific database). This set is called a persistence context. The EntityManager has methods for adding objects to the managed set (persisting), and for retrieving objects from it. Once an object is managed by the EntityManager any changes to it will automatically be saved to the database when the associated transaction ends. IS Course Info11

Getting the EntityManagerFactory and EntityManager We use annotation to get an EntityManagerFactory Then we call createEntityManager() to get the EntityManagerFactory emf ; EntityManager em = emf.createEntityManager(); IS Course Info12

Persisting objects New entities are persisted using the persist() method. EntityManager em; Employee emp = new Employee("Kongen", ); em.persist(emp); IS Course Info13

Retrieving objects using primary key Objects can be looked up by primary key with the find() method: EntityManager em;... Employee emp = em.find(Employee.class, 3); The parameters are the class of object to look for, and the object’s primary key. find() returns null if there is no object of the specified class with the specified primary key IS Course Info14