Creating a Relational Descriptor (ELUG)
This section describes how to create relational descriptors. For information on how to create more than one type of descriptors, see Creating a Descriptor.
After you create a descriptor, you must configure its various options (see Configuring a Descriptor) and use it to define mappings.
For complete information on the various types of descriptor that EclipseLink supports, see Descriptor Types.
For more information, see Introduction to Relational Descriptors.
Creating a Relational Descriptor
How to Create a Relational Descriptor Using Workbench
Using Workbench, you can create the following types of descriptor in a relational project:
Creating Relational Class DescriptorsConfiguring Project Classpath), Workbench creates a relational class descriptor for it. A class descriptor is applicable to any persistent object except an object that is owned by another in an aggregate relationship. In this case, you must describe the owned object with an aggregate descriptor (see Creating Relational Aggregate Descriptors). Using a class descriptor, you can configure any relational mapping except aggregate collection and aggregate object mappings.
Creating Relational Aggregate DescriptorsConfiguring a Relational Aggregate Collection Mapping and Configuring a Relational Aggregate Object Mapping), you must designate the target object's descriptor as an aggregate (see Configuring a Relational Descriptor as a Class or Aggregate Type).
Creating Relational Interface DescriptorsConfiguring Project Classpath), Workbench creates an interface descriptor for it.
An interface is a collection of abstract behavior that other classes can use. It is a purely Java concept and has no representation on the relational database. Therefore, a descriptor defined for the interfaces does not map any relational entities on the database.
The interface descriptor includes the following elements:
- The Java interface it describes.
- The parent interface(s) it implements.
- A list of abstract query keys.
An interface descriptor does not define any mappings, because there is no concrete data or table associated with it. A list of abstract query keys is defined so that you can issue queries on the interfaces (see Configuring Interface Query Keys). A read query on the interface results in reading one or more of its implementors.
How to Create a Relational Descriptor Using Java
This example shows how to create a relational descriptor using Java code.
Creating a Relational Descriptor in Java
RelationalDescriptor descriptor = new RelationalDescriptor(); descriptor.setJavaClass(YourClass.class);
To designate a relational descriptor as an aggregate, use ClassDescriptor method descriptorIsAggregate. For a RelationalDescriptor configured as an aggregate, you do not define a primary key, but when using Java, you must configure the associated table (see Configuring Associated Tables) and field mappings (see Introduction to Mappings).
To allow a relational descriptor to participate in an aggregate collection mapping (see Aggregate Collection Mapping), use ClassDescriptor method descriptorIsAggregateCollection. For a RelationalDescriptor configured for use with an aggregate collection mapping, you do define primary keys (see Configuring Primary Keys) and an associated table (see Configuring Associated Tables), but you do not have to map the primary keys if they are shared from their parent.
To configure a relational descriptor for an interface, use ClassDescriptor method setJavaInterface, passing in the java.lang.Class of the interface. You should only use an interface descriptor for an interface that has multiple implementors. If an interface has only a single implementor, then rather than creating an interface descriptor, just set the implementor descriptor's interface alias (see Configuring Interface Alias).