Developing EJB 3.0 applications using Apache OPENJPA, part 2nd: Developing the first open JPA application

Source: Internet
Author: User
Tags character set mysql database java se

In the previous section, we learned about the basic features of the EJB 3.0 standard and OpenJPA, and now we're going to start talking about how to use OpenJPA to develop enterprise applications. In this article, we will assume that there is a Animal object, in one scenario, we need to use the tools and interfaces provided by the OpenJPA framework to complete the Animal object persistence, property modification, deletion, lookup function. This article describes the steps and methods for using OpenJPA development with simple text and code, and how to use the tools provided by OpenJPA to assist with development tasks during the development process.

Download and install OpenJPA

Support Environment Preparedness

Since OpenJPA is a framework based on annotation mechanisms, which requires JDK 5.0 or above, make sure that JDK 5.0 is already downloaded and installed on the working machine.

In the demo process, we need a database as the target database for object persistence. For simplicity and convenience, we chose to use the MySQL database, so you need to download the MySQL database installation package. If you need a good MySQL support Chinese characters (GB2312 encoding), you can choose to download MySQL 5.0 or above version, the installation of the time to select the database character set for GB2312 can.

Download, install OpenJPA

The latest stable version of OpenJPA is Open JPA 0.97. OpenJPA installation is relatively simple, just want to download the compressed file can be extracted. Let's assume that the downloaded compressed package is uncompressed to the C:/OPENJPA directory (this directory will be referenced using%openjpa_home% later in this article).

Using OpenJPA to develop EJB 3.0 applications

Once the OpenJPA is successfully installed, we can start using the OpenJPA framework to develop EJB 3.0 applications. In the following sections we will cover the main steps in developing EJB 3.0 applications using the OpenJPA framework. In order to focus the description on the OpenJPA itself without involving too many other content, in this demo scenario, we use OpenJPA in lightweight applications that are developed based on the Java SE environment rather than the EJB container, about how to configure the usage in Java EE Openj PA will be another topic that will not be covered in this article, and will be discussed in subsequent articles in this series.

Typically, developing a persistence layer using the OpenJPA framework consists of the following steps:

Write (or modify) OpenJPA configuration file;

In non-Java EE environments, OpenJPA typically use meta-inf\persistence.xml files in CLASSPATH environments to create entitymanagerfactory, and each managed Java entity class must be in the Persis Tence.xml can be eneitymanager processed after registration.

Design Java objects According to business needs, write corresponding Java entity classes;

Compiling Java entity classes with JDK;

Using the tools provided by OpenJPA-pcenhancer to enhance (enhance) the compiled Java entity classes, enhanced classes can provide better performance, flexible "lazy load" and other aspects of the advantages of more detailed information please refer to the OpenJPA Help documentation.

Generate database definition files (DDL) from Java objects using the tools provided by OpenJPA Mappingtool;

You can maintain consistency between Entity and the database directly through the Mappingtool tool, or you can use the database definition file (DDL) generated by the Mappingtool tool to create the database structure that is required to apply the normal operation.

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.