In this section we will discuss about the Java Persistence API.
This section will describe you all the aspects of JPA such as what is JPA, architecture of JPA, features of JPA, JPA entities, entity inheritance JPA, how to manage entities in JPA, JPA querying entities.
What is JPA ?
JPA is also called Java Persistence API that facilitate developers to manage relational data using ORM (object/relational mapping). JPA, a standard persistence API is added since Java EE 5 specification. Initially JPA was introduced with EJB 3.0 under the JSR 220 specifications. JPA was introduced for simplifying the EJB entity beans programming model. Using JPA a Java developer can persist data for the desktop application as well as web application. JPA uses annotations so it requires the JDK 1.5 or higher version of Java.
JPA was introduced to simplify the EJB entity beans programming model. JPA persists the Java objects to the relational database using metadata. It maps the Java objects to the relational database table. Like SQL JPA has has the support of a query language to execute queries. It can execute both static and dynamic queries. JPA can be used with the various ORM frameworks like, Hibernate, Toplink from Oracle, iBatis, etc.
JPA has the various features that attracts developers to use persist data in the database table. Some of these features are as :
Persistence entity is a Java class whose state has to be persisted into a relation database table. Each row of this table is constituted as the instance of the entity class. There can be a relationship between entities and they can be expressed through object/relational metadata. This metadata can be defined either directly using annotations inside the entity class or by creating a XML file.
Entity inheritance JPA
Entity inheritance in JPA specifies the entities inheritance. An entity class can inherit non-entity classes and the non-entity classes can inherit entity.
How To Manage Entities In JPA ?
javax.persistence.EntityManager manages the Entities in JPA. Finds the entities in the data store using find() method of EntityManager with their primary key. Manage the life cycle of entity instances. Persist the entity instance.
JPA Querying Entities
There are various methods provided by JPA for querying entities. Java Persistence Query Language provides the simple query language like SQL. Java Persistence Criteria API provides to create typesafe queries.
For reading more about JPA please go through the link http://www.roseindia.net/jpa/index.shtml.
For JPA example click here http://roseindia.net/jpa/jpa-examples.shtml.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial