Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/Foundation/DynamicPersistence


Simple Example using EclipseLink Dynamic Persistence

Definition

Dynamic Persistence is defined as the ability to create a dynamic persistent entity and use it within an application without a-priori the entity's Java .class being present on the classpath (or in some .jar/.war archive).

The purpose of Dynamic Persistence is to enable simplified data access where only mapping information is required and no concrete Java model is required. This allows applications with dynamic storage requirements to avoid coupling to static classes or require specialized handling of new types. The application uses standard EclipseLink APIs to read, create, modify, and remove dynamic persistent entities from their data stores based on types that are either defined in XML mapping files or are constructed within the running application.

Example

ScottTigerEmpDept.png The classes from the new package org.eclipse.persistence.dynamic are used to construct a simple persistence example: DynamicClassLoader, DynamicHelper, and DynamicTypeBuilder:

//build a shared session (a.k.a. <tt>ServerSession</tt>)
...
DynamicHelper helper = new DynamicHelper(getSharedSession());
DynamicClassLoader dcl = helper.getDynamicClassLoader();
Class<?> javaType = dcl.createDynamicClass("model.Simple");

Back to the top