Migrate legacy hibernate applications to OPENJPA and EJB 3.0 (i)

Source: Internet
Author: User
Tags pack websphere application server java se

Introduction: Learn how to migrate Hibernate application source code, Object Relational mappings, and configuration parameters to OpenJPA by using the equivalent functionality in EJB 2.1 and OpenJPA and EJB 3.0 to compare features and functionality in Hibernate applications.

Introduction

Hibernate is an open source persistence and query framework that provides object-related mappings of traditional Java™ objects (POJO) to relational database tables, as well as data query and retrieval capabilities. The Apache OpenJPA Project will provide a similar open source persistence and query framework for POJO entities as defined in the EJB 3.0 Java Persistence API specification. This article describes the common Hibernate scenarios in Enterprise javabeans™ (EJB) 2.1 and compares them to the equivalent scenarios implemented in OpenJPA and EJB 3.0. Specifically, you can check the Hibernate application source code, Object Relational mappings, and configuration parameters and compare them to the equivalent OpenJPA source code, mapping, and configuration. The comparisons shown here not only give you an idea of how to make these changes, but also demonstrate that migrating legacy Hibernate applications that use these common scenarios to OpenJPA is fairly straightforward.

While this article focuses on migrating legacy Hibernate applications to OpenJPA, if you are familiar with Hibernate, you'll find value in it and want to use the new JPA specification as soon as possible and use the OpenJPA persistence Provider for new application development.

This article assumes that you are familiar with the basic concepts of Hibernate and will specifically introduce the Hibernate 3.0 implementation. All of the examples in this article have been run in Hibernate 3 in EJB 2.1, and OpenJPA 0.9 with ibm®websphere®application Server V6.1 Feature Pack for EJB 3.0 .7 has been run.

The reasons for migrating legacy Hibernate applications to OpenJPA are manifold. For example, Hibernate is a nonstandard, object-relational mapping, and persistence management solution. Hibernate 3 requires a JDK 1.3.1 or later version. By contrast, OpenJPA can implement the JPA specification, which is a core part of the Java 5 specification, and the implementation of the WebSphere application Server V6.1 Feature Pack for EJB 3.0 is based on that specification. For more information about these products, see resources.

For the purposes of this article, JPA represents the specification, and OpenJPA represents the implementation of the JPA specification.

This article does not describe all the features and features of Hibernate, but describes the best practices that are often used in this area.

Migrating Hibernate Application Source code

The Java Persistence API (JPA) is introduced as part of the EJB 3.0 specification (JSR220) to enable the entire Java community to support a standard, single, persistent API. JPA will use the best ideas of the Hibernate, TopLink, Java Data Objects, and Container Managed Persistence (EJB-CMP) 2.1 specifications.

JPA applies to Java Platform Standard Edition (Java SE) and Enterprise Edition (Java EE) environments because it represents entities that can be managed by the JPA persistence provider (such as OpenJPA) Pojo. The metadata about object-relational mappings for entities is specified using Java 5 annotations or in XML descriptors. Entities are used to persist Java objects to a database.

There are a number of JPA persistence providers. IBM's JPA specification implementation is based on the Apache OpenJPA project. With the release of these JPA persistence providers, customers can now encode standard APIs without having to make decisions between incompatible non-standard persistence providers.

To help you migrate legacy Hibernate applications to OpenJPA, this section compares the Hibernate non-standard APIs that are commonly used with the equivalent OpenJPA standard APIs. This section first compares the classes and interfaces used, and then compares the APIs through a general usage scenario.

The following sections provide detailed information:

Classes and Interfaces

Run-time configuration

Session Management

Transaction management

Entity Management

Detached entities

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.