Our Recommendation

Monday, December 13, 2010

JPA persistence simplified: introduction to the persistence of Java API (JavaBoutique)

by Jeyarani Venkatasamy

Qanywhere Java persistence (PPA) is the specification for the persistence of Java objects to relational databases using popular object relational mapping (ORM) technology. Taking advantage of Enterprise JavaBeans (EJB 3.0) JSR 220 app provides a standard based on the POJO and ORM to persist data between Java applications. APA relies on ideas, concepts and standards such as the TopLink, prolonged persistence frameworks and Java Data Objects (JDO), as well as the persistence of managed by previous EJB container.


One of the major benefits of APP is that it is an independent API and can integrate nicely with J2EE / Java EE as J2SE / Java SE applications. APP uses metadata to map persistence to the tables of the database objects, and it supports a SQL-like query language to facilitate the process of querying the database. The JPA query language can be used to perform static and dynamic queries.


In this article I will present the APP list its benefits and architecture with a demonstration application then to explain how it works and how to implement.


APP requires fewer classes and interfaces that older persistence solutions and it also virtually eliminates the annotations long deployment descriptors. It eliminates the need for code search and uses dependency injection. Here are the main advantages of the APP.

Simplify persistence technologyORM framework independence - the persistence of the third party providers may be snap-ins without any changes.Data cod-level can be saved in the ORM way.Supported industry leadersProvides - Java persistence query language better QLMakes EJB it easier test entities outside of the EJB containerCan be used outside of the container

The concept of the APP includes three components entity EntityManager EntityManagerFactory. Figure 1 illustrates the primary components of architecture of the JPA.



 
Click here to enlarge the image
Fig.1. Components of the architecture of the JPA


Entity is the (POJO) persistence object that represents a record in the database table. The entity is a simple, easy to develop annotated POJO class. These are the characteristics of an entity.

An entity can be persisted to the relational database.An what entity is identified by a persistent identity (i.e. the table's primary key) .An entity supports transactions.An entity supports inheritance.

EntityManager interface provides the API for interacting with the entity. Some of the functions provided by EntityManager API are:

persist - this method is used to register a new entity .merge - this method is used to update the status of an entity in the database .remove - this method is used to delete the instance of the entity.

The EntityManagerFactory is used to create an instance of EntityManager. When an application has no EntityManagerFactory or shuts down the application, then it is necessary to close the instance of EntityManagerFactory. After the closure of the EntityManagerFactory its EntityManagers are also closed.


Let's look at how app works by examining the persistence of a customer entity in a database. We need three artifacts to implement consistent app program Demo:

Entity ranked persistence.xml Intent class (or client) through the intermediary of which insert, update, or find an entity.

The following table lists the client table schema.


Here's the client table creation script:


Create the customer table (CUST_ID number (5) not NULL, FIRST_NAME VARCHAR2 (50) NOT NULL, LAST_NAME VARCHAR2 (50), VARCHAR2 (50) STREET, CITY, VARCHAR2 (25), ZIP_CODE VARCHAR (10) LAST_UPDATED_TIME TIMESTAMP NOT NULL, PRIMARY KEY (cust_id) constraint cust_Id_PKEY);


New review:

Time management made easy with Quartz Enterprise job scheduler
Why not just use Java timer API? This open source API programming boasts simplicity, ease of integration, a set of features have and it's free!


New applet:

Reverse complement
Reverse complement is a simple applet that converts DNA or RNA sequences into three useful formats.


Java WebDeveloper
Many Java information webdeveloper.com


WDVL Java
Comprehensive Java Web Developer's virtual library resources.


ScriptSearch Java
Free download hundreds of files from Java code.


jGuru: your view of the Java universe
Customizable portal with eLearning, FAQs, regularly new updates and tutorials.




No comments:

Post a Comment