October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Getting Started with EclipseLink and JPA 2

  • December 15, 2010
  • By KL Nitin, Mahalakshmi K
  • Send Email »
  • More Articles »

Data persistence plays a vital role in Java enterprise applications. The Java Persistence API (JPA), initially released as part of the Java EE 5 specification, was very useful for implementing data persistence when building Java EE applications. JPA 2, the latest version released as part of Java EE 6, introduces various new and interesting features.

Being a specification, JPA must be implemented by reference implementers or as products like TopLink Essentials (reference implementation for JPA 1.x), Hibernate, OpenJPA, etc. The reference implementation of JPA 2 is EclipseLink (the default implementation), which is an open source ORM solution from the Eclipse Foundation. The latest release of EclipseLink at the time of writing was EclipseLink 2.1.1, which was released in August 2010.

In our previous Developer.com articles, we explored many of the new features in JPA 2 such as new annotations, criteria queries and pessimistic locking. In this article we introduce EclipseLink and explain how to use it in JPA 2 applications for both Java SE and Java EE environments. We explain the features and provide several code snippets and snapshots for building a demo application in the Eclipse IDE. To develop the demo app, we used Eclipse 3.6 (Eclipse Helios) because it supports Java EE 6 completely, but Eclipse 3.5 (Eclipse Galileo) and NetBeans will work just as well.

Introducing EclipseLink

EclipseLink, the reference implementation of JPA 2 can be downloaded from http://www.eclipse.org/eclipselink/downloads/.

The two main JARs needed for building JPA 2 applications are:

  • eclipselink.jar
  • javax.persistence.jar

When building JPA 2 applications either in NetBeans or Eclipse, the only requirement is to add these JAR files into the project classpath. The developer need not bother with installing any other extra application to make the JPA 2 application work.

Apart from providing an implementation for the JPA 2 specification, EclipseLink also adds a set of new annotations as part of the org.eclipse.persistence.annotations package. These annotations can be used in conjunction with the JPA 2 standard annotations. A few of the newly introduced annotations in EclipseLink are listed in the table below.

Annotation

Description

@BasicMap

For storing a collection of maps that store key value pairs

@JoinFetch

For enabling joining of related objects while querying the database

@Mutable

For marking that the value of the property cannot be modified

@BasicCollection

For storing a collection of simple types in an entity


Tags: EclipseLink, JPA 2

Originally published on http://www.developer.com.

Page 1 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel