Use Apache OPENJPA to develop EJB 3.0 applications, part 1th: OPENJPA and EJB 3.0

Source: Internet
Author: User
Tags inheritance require serialization

Brief introduction:

The Java Persistence API (JPA) is the newly introduced data persistence programming model of EJB 3.0, which leverages the annotations (Annotation) and object/relationship mappings in Java 5 to provide simpler and more easy-to-use programming for data persistence. This series of articles will provide a comprehensive overview of its open source implementation-apache OpenJPA, providing detailed guidance for learning JPA standards and using OpenJPA for practical application development.

This paper is the first part of the series, it summarizes the impedance detuning (impedance mismatch) between relational database and object-oriented, introduces the corresponding solution of EJB 3.0 JPA Standard, and gives a preliminary introduction to OpenJPA.

relational database and object-oriented

Almost all enterprise applications require persistent data, and enterprise applications without data persistence requirements are almost impossible to present in the current market environment. Because of the popularity of relational data, we typically refer to data persistence as a means of persisting data to a relational database. Relational data is a structured way of managing data, and developers can manipulate databases only through SQL.

The Java language is inherently an object-oriented programming language, in the Java world, the processed content is organized into an object, there are inheritance, reference relationships between objects and objects, such a relationship can not be directly reflected in a relational database in a simple way. Therefore, there exists impedance detuning (impedance mismatch) between relational database and object-oriented object.

We use a simple example to illustrate the difficulty that this impedance mismatch poses to enterprise application developers. Suppose there are three Java classes in enterprise applications: Animal, fish, and Dog, where fish and Dog are Animal subclasses. In the Java world, Fish and Dog can be treated as Animal objects. But if we switch to a relational database, and these three objects are usually kept in their respective tables, assuming that they correspond to Animal tables, fish tables, and DOG tables, and if you want to maintain Animal and fish inheritance, we need to use SQL's federated query statement to detect Animal All attributes and all of the properties of Fish, and are associated with some foreign key:

Select animal.*,fish.* form animal,fish where animal.id = Fish.id

From this simple example, we can see that an enterprise application developer needs to master two ideas of object-oriented and relational databases at the same time, and must ensure that the mapping between them is correct, otherwise the enterprise application is not guaranteed to be correct, which is a challenge for enterprise application developers, so the Java society The region has been looking for ways to unify the ideas of object-oriented and relational databases, and this effort has contributed to the development of sustainable technologies.

Sustainable Technologies in development

Persistence is one of the core requirements of enterprise application development, it has also been one of the hottest topics in the Java community in recent years, and in the Java Community's efforts to address persistent data management, there have been a number of technical solutions that have emerged to try to solve this problem, from the earliest serialization to JDBC, JDO, ORM, Object database, EJB 2.X, however, these technologies all have a variety of limitations, affecting them to become the best choice. Here's a quick review of the technologies in the Java community that have tried to provide a complete solution for persistent data management.

Serialization of

Serialization is the earliest implementation that manages persisted data and is a data persistence solution built into the Java language. It works by converting an object into a byte stream, generating a stream of bytes that can be transmitted over the network or stored in a file. Serialization is very easy to use, but the limitations are also very large, because serialization must take all objects out at once, which limits its application in processing large amounts of data, it cannot undo modifications to an object in the event of an update failure, making it unusable for applications that require strict data consistency. Multithreading or multiple applications cannot read and write the same serialized data concurrently and without conflict, nor can it provide query functionality.

Jdbc

Many developers of enterprise applications choose to use JDBC to manage data in relational databases. In the case of relative serialization, JDBC overcomes many disadvantages: it supports processing large amounts of data, guaranteeing consistency of data, supporting concurrent access to information, and providing SQL query language to find data. Unfortunately, JDBC does not provide the ease of serialization. The relational model used by JDBC is not designed to save objects, forcing developers to choose to discard object-oriented programming while processing persistent data, or to develop proprietary solutions that map object-oriented features such as inheritance between classes and relational databases.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.