Download JPA

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JAVE PERSISTENCE API (JPA)
1
OBJECT RELATIONAL
MAPPING(ORM)

Ánh xạ dữ liệu của đối tượng vào trong cơ sở dữ
liệu quan hệ.
2
GIỚI THIỆU JAVA PERSISTENCE API()
JPA là một đặc tả Java cho việc truy xuất, quản lý
dữ liệu giữa các object/class và một cơ sở dữ liệu
quan hệ sử dụng công nghệ ORM (Object to
Relational Mapping).
 Được phát triển như một phần của Java
Specification Request (JSR) 220

Mục tiêu làm đơn giản hóa EJB CMP entity beans.
 Đóng gói trong javax.persistence


JPA có thể sử dụng cả trong môi trường J2SE lẫn
J2EE.
3
KIẾN TRÚC JPA
4
MAPPING MỘT ENITTY
Entity là một POJO (Plain Old Java Object)
 Được map bằng một trong hai cách

Mô tả trong XML descriptor
 Sử dụng annotations trong từng class

Được xác định với @Entity
 Khóa chính được thông qua @Id


Chứa các persitent fields hoặc các properties
Các thuộc tính được truy xuất thông qua
getters/setters là “properties”
 Các thuộc tính được truy xuất trực tiếp được gọi là
“fields”

5
PERSISTENCE CONTEXT
Đóng vai trò như một connection giữa thể hiện
của entity trong bộ nhớ và database.
 Xác định trong file cấu hình persistence.xml
 Được thao tác thông qua EntityManager.

Entities
Persistence
Context
Database
6
ENTITYMANAGER
Dùng để truy xuất và quản lý trạng thái của
entity.
 Tạo thông qua lớp EntityManagerFactory

7
ENTITY RELATIONSHIPS
Các kiểu liên kết giữa các entity
 Các liên kết được thực hiện thông qua file
mapping orm.xml hay sử dụng các annotations

javax.persistence.OneToOne
 javax.persistence.OneToMany
 javax.persistence.ManyToOne
 javax.persistence.ManyToMany

8
QUERIES
Queries
Dynamic
Named
Native
9
DYNAMIC QUERIES
10
NAMED QUERIES
11
NATIVE QUERIES

Native queries chứa câu lệnh SQL tự nhiên
Query query = em.createNativeQuery("SELECT *
FROM t_customer", Customer.class);
List<Customer> customers = query.getResultList();
12
REFERENCES
[1]. Antonio Goncalves, Beginning Java™ EE 6 Platform with
GlassFish™ 3, Apress, 2009
[2]. Rima Patel Sriganish, Gerald Brose, Micah silverman, Mastering
Enterprise JavaBeans 3.0, Wiley, 2006
[3]. Kent Ka Iok Tong, Beginning JSF™ 2 APIs and JBoss® Seam,
Apress, 2009
13
THE END
Thank you very much!!
14
Related documents