Jump to: navigation, search


This example catalogs the migration from Hibernate(TM) Annotations to EclipseLink JPA with its custom annotations. This is a work in progress so please feel free to add your comments or additional content. If you are trying to migrate from a Hibernate annotation that is not covered here please post a question to the EclipseLink newsgroup.

Entity Annotations

These annotations are configured on the entity class.


		selectBeforeUpdate = true,
		dynamicInsert = true, dynamicUpdate = true,
		optimisticLock = OptimisticLockType.ALL,
		polymorphism = PolymorphismType.EXPLICIT)

Dynamic Insert/Update

By default EclipseLink will always insert all mapped columns and will only update the columns that have changed. If alternate operations are required then the queries used for these operations can be customized using API, SQL, or Stored Procedures.

Optimistic Locking

EclipseLink's optimistic locking functionality supports all of the Hibernate locking types and more. This table translated the locking types from Hibernate's @Entity(optimisticLock) attributes into the EclipseLink locking policies which can be configured with @OptimisticLocking or in EclipseLink's ORM.XML.

Hibernate's OptimisticLockType Description EclipseLink OptimisticLocking
NONE no optimistic locking EclipseLink defaults to no optimistic locking
VERSION use a column version JPA @Version

or EclipseLink @OptimisticLocking(type = OptimisticLockingType.VERSION_COLUMN)

DIRTY dirty columns are compared JPA @Version or EclipseLink @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
ALL all columns are compared @OptimisticLocking(type = OptimisticLockingType.ALL_COLUMNS)

Additionally EclipseLink provides support for comparing a specific set of selected columns using OptimisticLockingType.SELECTED_COLUMNS. This approach allows you to select the critical columns that should be compared if the CHANGED or ALL strategies do not meet your needs.

Custom Sequence Generator

In Hibernate a custom generator for sequence values can be defined and used as:

   @GeneratedValue(generator = "system-uuid")
   @GenericGenerator(name = "system-uuid", strategy = "mypackage.UUIDGenerator")
   public String getTransactionGuid()

With EclipseLink a custom sequence generator can be implemented and registered for use using the @GeneratedValue. See: How to use Custom Sequencing (ie. UUID) for more details.

Mapping Annotations



The @ForeignKey annotation allows developers to define the name of the Foreign Key to be used during schema generation. EclipseLink does generate reasonable names but does not provide an annotation or eclipselink-orm.xml support for specifying the name to use. When migrating the recommended solution is to have EclipseLink generate the schema (DDL) commands to a script file instead of directly on the database. The script can then be customized to use different names prior to being used.

Note: The foreign key name is not used by EclipseLink at runtime but is required if EclipseLink attempts to drop the schema. In this case the drop script should be generated to file and customized to match the foreign key names used during creation.


The @Cache annotation is used to configure the caching of entities and relationships. Since EclipseLink uses an entity cache instead of a data cache the relationships are automatically cached. In these cases the @Cache should simply be removed during migration.

When @Cache is used on an entity it is similar in usage to EclipseLink's @Cache annotation. See the Eclipse User Guide on JPA Extensions for complete details of the @Cache annotation and equivalent eclipselink-orm.xml configuration values.



The @Where annotation allows developers to define additional criteria or filters to be used when querying for this entity type. In EclipseLink this is referred to as