CIS 764Kansas State UniversityDirected by Riyad AlRihieliJava Persistence APIJPA
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?
Introduction One of the significant improvement in the java plateform is the JPA. This is because it offers developers much easier wayto access and manipulate relational data in the javaapplication. There is more than that . The reaction to the java persistence has beenextremely positive from the java community JPA has had a good start with strong acceptance bythe java developers.
What is JPA? JPA stands for a java persistence API which is Javax.Persistence Package. Basically , it is a Java programmingLanguage framework that helps developers to control relationaldata in java platform. The JPA exactly was described as part ofthe EJB3.0 , which is a replacement to the EJB2CMP EntityBeans specification, specification . As we know that a javapersistence API is the newest of several Java persistencespecifications.
What is persistence consists of.. ? Any persistence consists of there Areas: The API, defined in the Javax. Persistencepackage The java persistence Query Language Object / relational meta data.
What JPA does exactly? JPA defined a runtime Entity Manger APIprocessing queries and transaction on theobjects against the database. It is defined a objects-level query languageJPQL to allow querying of the objects fromthe database.
What is java persistence query language isused for? Basically, JPQL stands for Java PersistenceQuery Language. And it is used to makequeries for against entities stored in arelational database. Queries resemble SQLqueries in syntax, but operate against entityobjects rather than directly with databasetables.
Is there relationship between the JPAand EJB? The answer is yes , there is a relationshipbetween Java Persistence API(JPA) andEnterprise Java Beans (EJB). java persistence is a part of EJB which is it partof the Java EE5. Also, developers do not requireEJB container in order to run applications, whichuse persistence. The API might be usedoutside the container within Java EE andcan even stand alone in the JavaPlatform, Standard Edition (Java SE).
Why we should use the Java PersistenceAPI? There is a great Motivation for creating JPA Many enterprise Java developers have been usinglightweight persistent objects, which supported byopen-source frameworks or data access objects as asubstitute of entity beans. This is because entitybeans and enterprise beans were too heavyweightand complicated. Furthermore, they could only beused in Java EE application servers.
Comparing the EJB3 and the EJB2 In fact, there are many differences, which are the advantages ofEJB3.0, between the EJB 2.1 version EJB 3.0 version :The EJB 3.0 EJB 2.11. Annotations and default replacea lot of cumbersome code.2. Persistence entities are simpleconcrete ,and plain old javaobject ( POJO)classes thatdevelopers can run as theywould any other simple javatechnology classes3. The API provides capabilities ,such as inheritance andpolymorphism.1. Developers have to createlengthy, complicated ,anddeployment descriptors inthe application that use EJBtechnology.2. Developers have toimplement the variousabstract classes , interfaces,and interface methodswhether they use them ornot.3. Those capabilities are not
Example: to illustrate more In the EJB 3.0 entity, java developers do not require to codeinterfaces such as LocalAddressHome and LocalAddress - or even adeployment descriptor. What they need to have just the entity class.This is because in the applications EJB 3.0 version, whats requiredfor an entity has been reduced from three classes -- for local interfacesand a business class -- to one entity class. In addition to that , theydon’t need to implement the EJBObject and EJBLocalObjectinterfaces. For instance, a session bean now need only a bean classand a business interface, which is a simple Java technology interface.
Let’s look to Another Example In this example, java developers can map a hierarchy ofentities, where one entity subclasses another, to a relationaldatabase structure, and submit queries against the base class.The queries are treated polymorphically against the entirehierarchy.
Summary of the Advantages of JPA JPA Requires Just smaller number of classes andinterfaces It gets rid of lengthy deployment descriptors throughannotations JPA Addresses most typical specifications throughannotation 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 theJPA Supports a Java Persistence query language -- animproved EJB QL Makes it easier to test entities outside of the EJB container Can be used outside of the container
what is my Tutorial ?double Click on the picture to see the tutorial
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 Edort.(http://java.sun.com/javaone/sf/2007/articles/persistence2_0.jsp) Article : The Java Persistence API - A Simpler Programming Model forEntity Persistence byBy Rahul Biswas and Ed Ort, May 2006(http://java.sun.com/developer/technicalArticles/J2EE/jpa/)
QuestionsIf you want to know more about JPA ,just read this bookBy