Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Development/Dynamic/def1

< EclipseLink‎ | Development‎ | Dynamic
Revision as of 16:28, 27 August 2009 by Unnamed Poltroon (Talk) (Dynamic Persistence)

Dynamic Persistence

Dynamic Persistence is defined as the ability to create a persistent entity class and use it within an application without the Java class existing (no .java or .class files). This is typically accomplished by creating a class on-the-fly with a custom ClassLoader that uses a bytecode manipulation library (such as ASM or some other library [1]).

Dynamic Persistence is - in essence - a trick with ClassLoaders. EclipseLink's meta-data describes a persistent entity in terms of a Descriptor which owns (one or more) Mappings that represent a class' member fields. The class' info is string-based - for instance in code:

RelationalDescriptor addressDescriptor = new RelationalDescriptor();
addressDescriptor.setAlias("address");
addressDescriptor.setJavaClassName("com.foo.bar.Address");

or XML:

<?xml version="1.0" encoding="UTF-8"?>
<object-persistence version="Eclipse Persistence Services - {some version}"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:eclipselink="http://www.eclipse.org/eclipselink/xsds/persistence"
  >
  <name>relationships</name>
  <class-mapping-descriptors>
    <class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
      <class>com.foo.bar.Address</class>
      <alias>address</alias>

Because almost any value can be specified for the <class> (within the limits of Java naming requirements), there is the possibility that at runtime the class cannot be found. The trick is to provide a custom ClassLoader that upon detecting that com.foo.bar.Address does not exist, uses a bytecode manipulation library to create a class that agrees with the meta-data - in terms of the Mappings, their types, etc.

Back to the top