17
CIS 764 Kansas State University Directed by Riyad AlRihieli Java Persistence API JPA

Al rihieli persistence

Embed Size (px)

Citation preview

Page 1: Al rihieli persistence

CIS 764

Kansas State University Directed by Riyad AlRihieli

Java Persistence API

JPA

Page 2: Al rihieli persistence

Review Topics: Introduction what is the JPA? What is the JPA contains of? Why developers should Create the JPA? Is there Relationship between the EJB and JPA? What the JPA dose exactly? Sample process of java persistence API. Comparing between the EJB3 and the EJB2? What the advantages of using the JPA? what is my Tutorial ? Questions?

Page 3: Al rihieli persistence

Introduction

One of the significant improvement in the java plate form is the JPA.

This is because it offers developers much easier way to access and manipulate relational data in the java application.

There is more than that . The reaction to the java persistence has been

extremely positive from the java community JPA has had a good start with strong acceptance by

the java developers.

Page 4: Al rihieli persistence

What is JPA?

JPA stands for a java persistence API which is Javax. Persistence Package. Basically , it is a Java programming Language framework that helps developers to control relational data in java platform. The JPA exactly was described as part of the EJB3.0 , which is a replacement to the EJB2CMP Entity Beans specification, specification . As we know that a java persistence API is the newest of several Java persistence specifications.

Page 5: Al rihieli persistence

What is persistence consists of.. ?

Any persistence consists of there Areas: The API, defined in the Javax. Persistence

package The java persistence Query Language Object / relational meta data.

Page 6: Al rihieli persistence

What JPA does exactly?

JPA defined a runtime Entity Manger API processing queries and transaction on the objects against the database.

It is defined a objects-level query language JPQL to allow querying of the objects from the database.

Page 7: Al rihieli persistence

What is java persistence query language is used for?

Basically, JPQL stands for Java Persistence Query Language. And it is used to make queries for against entities stored in a relational database. Queries resemble SQL queries in syntax, but operate against entity objects rather than directly with database tables.

Page 8: Al rihieli persistence

Is there relationship between the JPA and EJB?

The answer is yes , there is a relationship between Java Persistence API(JPA) and Enterprise Java Beans (EJB).

java persistence is a part of EJB which is it part of the Java EE5. Also, developers do not require EJB container in order to run applications, which use persistence. The API might be used outside the container within Java EE and can even stand alone in the Java Platform, Standard Edition (Java SE).

Page 9: Al rihieli persistence

Sample Process of Using Java Persistence API

Page 10: Al rihieli persistence

Why we should use the Java Persistence API?

There is a great Motivation for creating JPA Many enterprise Java developers have been using

lightweight persistent objects, which supported by open-source frameworks or data access objects as a substitute of entity beans. This is because entity beans and enterprise beans were too heavyweight and complicated. Furthermore, they could only be used in Java EE application servers.

Page 11: Al rihieli persistence

Comparing the EJB3 and the EJB2

In fact, there are many differences, which are the advantages of EJB3.0, between the EJB 2.1 version EJB 3.0 version :

The EJB 3.0 EJB 2.11. Annotations and default replace

a lot of cumbersome code. 2. Persistence entities are simple

concrete ,and plain old java object ( POJO)classes that developers can run as they would any other simple java technology classes

3. The API provides capabilities , such as inheritance and polymorphism.

1. Developers have to create lengthy, complicated ,and deployment descriptors in the application that use EJB technology.

2. Developers have to implement the various abstract classes , interfaces, and interface methods whether they use them or not.

3. Those capabilities are not available in the EJB2.0

Page 12: Al rihieli persistence

Example: to illustrate more

In the EJB 3.0 entity, java developers do not require to code interfaces such as LocalAddressHome and LocalAddress - or even a deployment descriptor. What they need to have just the entity class. This is because in the application's EJB 3.0 version, what's required for an entity has been reduced from three classes -- for local interfaces and a business class -- to one entity class. In addition to that , they don’t need to implement the EJBObject and EJBLocalObject interfaces. For instance, a session bean now need only a bean class and a business interface, which is a simple Java technology interface.

Page 13: Al rihieli persistence

Let’s look to Another Example

In this example, java developers can map a hierarchy of entities, where one entity subclasses another, to a relational database structure, and submit queries against the base class. The queries are treated polymorphically against the entire hierarchy.

Page 14: Al rihieli persistence

Summary of the Advantages of JPA

JPA Requires Just smaller number of classes and interfaces It gets rid of lengthy deployment descriptors through

annotations JPA Addresses most typical specifications through

annotation defaults. JPA supports easier, cleaner, and standardized object-

relational mapping. It add support for polymorphism, and inheritance. Also, dynamic queries and named queries is added to the

JPA Supports a Java Persistence query language -- an improved

EJB QL Makes it easier to test entities outside of the EJB container Can be used outside of the container

Page 15: Al rihieli persistence

what is my Tutorial ?

double Click on the picture to see the tutorial

Page 16: Al rihieli persistence

References

Wikipedia ebsite ( http://en.wikipedia.org/wiki/Java_Persistence_API) Answer website http://www.answers.com/Java%20Persistence%20API http://java.sun.com/javaee/5/docs/tutorial/doc/bnbqa.html Project Using Generics with Java Persistence by Sean Brydon,

Inderjeet Singh (https://blueprints.dev.java.net/bpcatalog/ee5/persistence/generics.html)

Java Persistence API 2.0—A Great Start Gets Better (TS-4945) by Ed ort.(http://java.sun.com/javaone/sf/2007/articles/persistence2_0.jsp)

Article : The Java Persistence API - A Simpler Programming Model for Entity Persistence byBy Rahul Biswas and Ed Ort, May 2006 (http://java.sun.com/developer/technicalArticles/J2EE/jpa/)

Page 17: Al rihieli persistence

Questions

If you want to know more about JPA , just read this book

By