119 Configuring a Descriptor

This chapter describes how to configure TopLink project options common to two or more project types.

This chapter includes the following sections:

Table 119-1 lists the types of TopLink descriptors that you can configure and provides a cross-reference to the type-specific chapter that lists the configurable options supported by that type.

Table 119-2 lists the configurable options shared by two or more TopLink descriptor types.

For more information, see the following:

119.1 Configuring Common Descriptor Options

Table 119-2 lists the configurable options shared by two or more TopLink descriptor types. In addition to the configurable options described here, you must also configure the options described for the specific Descriptor Types, as shown in Table 119-1.

Table 119-2 Common Descriptor Options

Option to Configure Oracle JDeveloper
TopLink Workbench Java

Primary keys (see Section 119.2, "Configuring Primary Keys")

Supported Supported Supported

Read-only (see Section 119.3, "Configuring Read-Only Descriptors")

Supported Supported Supported

Unit of work conforming (see Section 119.4, "Configuring Unit of Work Conforming at the Descriptor Level")

Supported Supported Supported

Alias (see Section 119.5, "Configuring Descriptor Alias")

Supported Supported Supported

Comments (see Section 119.6, "Configuring Descriptor Comments")

Supported

Supported.

Unsupported.

Classes (see Section 5.7.2, "How to Configure Classes")

Unsupported.

Supported.

Unsupported.

Named queries (see Section 119.7, "Configuring Named Queries at the Descriptor Level")

Supported Supported Supported

Query timeout (see Section 119.8, "Configuring Query Timeout at the Descriptor Level")

Supported Supported Supported

Cache refreshing (see Section 119.9, "Configuring Cache Refreshing")

Supported Supported Supported

Query keys (see Section 119.10, "Configuring Query Keys")

Supported

Supported.

Supported.

Interface query keys (see Section 119.11, "Configuring Interface Query Keys")

Supported

Supported.

Supported.

Cache type and size (see Section 119.12, "Configuring Cache Type and Size at the Descriptor Level")

Supported

Supported.

Supported.

Cache isolation (see Section 119.13, "Configuring Cache Isolation at the Descriptor Level")

Supported

Supported.

Supported.

Unit of work cache isolation (see Section 119.14, "Configuring Unit of Work Cache Isolation at the Descriptor Level")

Unsupported.

Unsupported.

Supported.

Cache coordination change propagation (see Section 119.15, "Configuring Cache Coordination Change Propagation at the Descriptor Level")

Supported.

Supported.

Supported.

Cache expiration (see Section 119.16, "Configuring Cache Expiration at the Descriptor Level")

Supported.

Supported.

Supported.

Cache existence checking (see Section 119.17, "Configuring Cache Existence Checking at the Descriptor Level")

Supported.

Supported.

Supported.

EJB information (see Section 119.18, "Configuring a Descriptor with EJB CMP and BMP Information")

Supported.

Supported.

Supported.

Reading subclasses on queries (see Section 119.19, "Configuring Reading Subclasses on Queries")

Supported.

Supported.

Supported.

Inheritance for a child class descriptor (see Section 119.20, "Configuring Inheritance for a Child (Branch or Leaf) Class Descriptor")

Supported.

Supported.

Supported.

Inheritance for a parent class descriptor (see Section 119.21, "Configuring Inheritance for a Parent (Root) Descriptor")

Supported.

Supported.

Supported.

Inheritance expressions for a parent class descriptor (see Section 119.22, "Configuring Inheritance Expressions for a Parent (Root) Class Descriptor")

Supported.

Supported.

Supported.

Inherited attribute mapping in a subclass (see Section 119.23, "Configuring Inherited Attribute Mapping in a Subclass")

Supported.

Supported.

Supported.

Domain object method as an event handler (see Section 119.24, "Configuring a Domain Object Method as an Event Handler")

Supported.

Supported.

Supported.

Descriptor event listener as an event handler (seeSection 119.25, "Configuring a Descriptor Event Listener as an Event Handler")

Unsupported.

Supported.

Supported.

Locking policy (see Section 119.26, "Configuring Locking Policy")

Supported.

Supported.

Supported.

Returning policy (see Section 119.27, "Configuring Returning Policy")

Supported.

Supported.

Supported.

Instantiation policy (see Section 119.28, "Configuring Instantiation Policy")

Supported.

Supported.

Supported.

Copy policy (see Section 119.29, "Configuring Copy Policy")

Supported.

Supported.

Supported.

Change policy (see Section 119.30, "Configuring Change Policy")

Unsupported.

Unsupported.

Supported.

History policy (see Section 119.31, "Configuring a History Policy")

Unsupported.

Unsupported.

Supported.

Wrapper policy (see Section 119.32, "Configuring Wrapper Policy")

Unsupported.

Unsupported.

Supported.

Fetch groups (see Section 119.33, "Configuring Fetch Groups")

Unsupported.

Unsupported.

Supported.

Amendment methods (see Section 119.35, "Configuring Amendment Methods")

Unsupported.

Supported.

Unsupported.

Mapping (see Section 121, "Configuring a Mapping")

Supported Supported Supported

119.2 Configuring Primary Keys

A primary key is a unique identifier (made up of one or more persistent attributes) that distinguishes one instance of a class from all other instances of the same type. You use primary keys to define relationships and to define queries.

For the descriptors shown in Table 119-3, you must configure a primary key and you must ensure that your class contains one or more persistent fields suitable for this purpose.

Table 119-3 summarizes which descriptors support primary keys.

Table 119-3 Descriptor Support for Primary Keys

Descriptor How to Use Oracle JDeveloper How to Configure Primary Keys Using TopLink Workbench
How to Configure Primary Keys Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

For a relational class (non-aggregate) descriptor, choose any unique database field or set of unique database fields from the descriptor's associated table (see Section 23.2, "Configuring Associated Tables").

For an EIS root descriptor (see Section 76.6, "Configuring an EIS Descriptor as a Root or Composite Type"), choose any unique attribute or text node or set of unique attributes or text nodes from the descriptor's schema context (see Section 76.2, "Configuring Schema Context for an EIS Descriptor").

119.2.1 How to Configure Primary Keys Using TopLink Workbench

To associate a descriptor with one or more primary keys, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Descriptor Info tab. The Descriptor Info tab appears.

    Figure 119-1 Descriptor Info Tab, Primary Key Options

    Description of Figure 119-1 follows
    Description of "Figure 119-1 Descriptor Info Tab, Primary Key Options"

Use this table to enter data in Primary Keys field on the descriptor's Descriptor Info tab to specify the primary key(s):

Field Description
Primary Keys To specify the primary keys for the table, click Add in order to do the following:

To remove a primary key, select the key and click Remove.


119.2.2 How to Configure Primary Keys Using Java

You can use Java to configure primary keys for the following:

119.2.2.1 Relational Projects

Use ClassDescriptor method addPrimaryKeyFieldName to specify the primary key field of the descriptor's table. This should be called for each field that makes up the primary key of the table.

If the descriptor has more than one table, and all other tables have the same primary key, use the ClassDescriptor method addPrimaryKeyFieldName to specify the the primary key in the first table.

If the descriptor has more than one table, and each table has a different primary key, use ClassDescriptor method addForeignKeyFieldNameForMultipleTable to map the source foreign key field name to target primary key field name.

119.2.2.2 EIS Projects

Use EISDescriptor method addPrimaryKeyFieldName to specify the primary key field of the descriptor's class. Call this method for each field that makes up the primary key.

119.3 Configuring Read-Only Descriptors

You can configure a relational class or EIS root descriptor as read-only. This indicates that instances of the reference class will never be modified.

Read-only descriptors are usually used within a unit of work as a performance gain, because there is no need to register, clone, and merge the read-only classes. For more information, see Chapter 113, "Introduction to TopLink Transactions".

In a CMP project, you can declare an entity bean as read-only within the TopLink deployment XML file. For more information, see Section 119.3.1, "How to Use Read-Only EJB CMP Entity Beans".

Table 119-4 summarizes which descriptors support read-only configuration.

Table 119-4 Descriptor Support for Read Only

Descriptor How to Use Oracle JDeveloper How to Configure Read-Only Descriptors Using TopLink Workbench
How to Configure Read-Only Descriptors Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS DescriptorFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors")

Note:

Relational aggregate and EIS composite descriptors get their read-only setting from their owner.

119.3.1 How to Use Read-Only EJB CMP Entity Beans

TopLink can declare an entity bean with container-managed persistence as read-only. This ensures that the entity bean cannot be modified and allows TopLink to optimize unit of work performance.

If an attempt is made to modify a read-only entity bean (create, update, or remove), TopLink immediately throws a javax.ejb.EJBException: TopLink does not wait until the transaction commits.

If an attempt is made to change a CMR field on a read-only entity bean, TopLink throws a javax.ejb.EJBException.

When TopLink is configured as the OC4J persistence manager, the TopLink read-only bean configuration replaces the OC4J READ-ONLY CMP concurrency mode.

119.3.2 How to Configure Read-Only Descriptors Using TopLink Workbench

To configure a descriptor as read-only use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Descriptor Info tab. The Descriptor Info tab appears.

    Figure 119-2 Descriptor Info Tab, Read Only Option

    Description of Figure 119-2 follows
    Description of "Figure 119-2 Descriptor Info Tab, Read Only Option"

Specify whether this descriptor is read-only or not.

119.3.3 How to Configure Read-Only Descriptors Using Java

Use ClassDescriptor method setReadOnly.

119.4 Configuring Unit of Work Conforming at the Descriptor Level

Conforming is a query feature that lets you include new, changed, or deleted objects in queries within a unit of work prior to committing the transaction. This feature enables you to query against your relative logical or transaction view of a data source.

Table 119-5 summarizes which descriptors support descriptor level unit of work conforming.

Table 119-5 Descriptor Support for Unit of Work Conforming

Descriptor How to Use Oracle JDeveloper How to Configure Unit of Work Conforming at the Descriptor Level Using TopLink Workbench
How to Configure Unit of Work Conforming at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors")

When you configure a descriptor to conform results in a unit of work, when you execute a query in the unit of work, TopLink filters the data source result set to the changes currently made in the unit of work. TopLink adds new or changed objects that correspond to the query's selection criteria and removes changed objects that no longer correspond to the query's selection criteria.

Note:

For EIS root descriptors, only deleted objects would be filtered, not new or changed objects.

Conforming can reduce performance. Before you enable a descriptor for conforming, be aware of its limitations (see Section 115.4.1, "How to Use Conforming") and make sure that conforming is actually necessary.

For examples, see the following:

119.4.1 How to Configure Unit of Work Conforming at the Descriptor Level Using TopLink Workbench

To conform a descriptor's results in a unit of work, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Descriptor Info tab. The Descriptor Info tab appears.

    Figure 119-3 Descriptor Info Tab, Conform Results in Unit of Work Option

    Description of Figure 119-3 follows
    Description of "Figure 119-3 Descriptor Info Tab, Conform Results in Unit of Work Option"

Enable or disable conforming: when enabled, this feature ensures that any queries for this descriptor will conform the data source result with the current changes in the unit of work. For more information, see Section 115.4.1, "How to Use Conforming".

119.4.2 How to Configure Unit of Work Conforming at the Descriptor Level Using Java

Use ClassDescriptor method setShouldAlwaysConformResultsInUnitOfWork(true).

119.5 Configuring Descriptor Alias

In EJB CMP, use the descriptor alias to specify the value of the ejb-jar.xml attribute abstract-schema-name. This is the logical name that is referenced in EJB QL queries. You should configure a descriptor alias for each entity bean with container-managed persistence. The descriptor alias defaults to the class name without a path information.

Table 119-6 summarizes which descriptors support descriptor alias configuration.

Table 119-6 Descriptor Support for Descriptor Alias Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Descriptor Alias Using TopLink Workbench
How to Configure Descriptor Alias Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported Unsupported

EIS DescriptorsFoot 1 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

Note:

The alias is also used in JPA–it is the entity name. This is the logical name referenced in JP QL queries. It defaults to the class name without a path information.

For more information, see "Introduction to EclipseLink JPA" chapter of EclipseLink Developer's Guide at http://wiki.eclipse.org/Introduction_to_EclipseLink_JPA_%28ELUG%29.

For more information, see the following:

119.5.1 How to Configure Descriptor Alias Using TopLink Workbench

To specify a descriptor alias, use this procedure:

  1. In the Navigator, select a descriptor.

  2. Click the Descriptor Info tab in the Property window.

  3. Figure 119-4 Descriptor Info Tab, Descriptor Alias Field

    Description of Figure 119-4 follows
    Description of "Figure 119-4 Descriptor Info Tab, Descriptor Alias Field"

In the Descriptor Alias field, enter an alias for this descriptor. For more information, see Section 119.5, "Configuring Descriptor Alias".

119.5.2 How to Configure Descriptor Alias Using Java

Use ClassDescriptor method setAlias passing in the descriptor alias as a String.

119.6 Configuring Descriptor Comments

You can define a free-form textual comment for each descriptor. You can use these comments however you whish: for example, to record important project implementation details such as the purpose or importance of a descriptor.

Comments are stored in the TopLink Workbench project, in the TopLink deployment XML file. There is no Java API for this feature.

Table 119-7 summarizes which descriptors support descriptor comment configuration.

Table 119-7 Descriptor Support for Descriptor Comment Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Descriptor Comments Using TopLink Workbench
How to Use Java

Relational Descriptors

Unsupported

Supported.

Unsupported

Object-Relational Data Type Descriptors

Unsupported Unsupported Unsupported

EIS Descriptors

Unsupported

Supported.

Unsupported

XML Descriptors

Unsupported

Supported.

Unsupported

119.6.1 How to Configure Descriptor Comments Using TopLink Workbench

To create a comment for a descriptor, use this procedure:

  1. In the Navigator, select a descriptor.

  2. Click the Descriptor Info tab in the Property window.

  3. Figure 119-5 Descriptor Info Tab, Comment Field

    Description of Figure 119-5 follows
    Description of "Figure 119-5 Descriptor Info Tab, Comment Field"

In the Comment field, enter a description of this descriptor.

119.7 Configuring Named Queries at the Descriptor Level

A named query is a TopLink query that you create and store, by name, in a descriptor's DescriptorQueryManager for later retrieval and execution. Named queries improve application performance because they are prepared once and they (and all their associated supporting objects) can be efficiently reused thereafter making them well suited for frequently executed operations.

If a named query is global to a Class, configure it at the descriptor level. Alternatively, you can configure a named query at the session level (see Section 89.13, "Configuring Named Queries at the Session Level").

Use named queries to specify SQL, EJB QL, or TopLink Expression queries to access your data source.

For EJB CMP entity bean descriptors, you must define a named query for every finder defined for the corresponding entity bean.

Note:

You can also use named queries in JPA (see "Using EclipseLink JPA Extensions for Stored Procedure Query" section of EclipseLink Developer's Guide at http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Stored_Procedure_Query). Because the scope of JPA named queries is global to the session, ensure that each named query has a unique name.

Using Oracle JDeveloper or TopLink Workbench, you can configure named queries for a subset of query types and store them in a descriptor's DescriptorQueryManager (see Section 119.7.1, "How to Configure Named Queries at the Descriptor Level Using TopLink Workbench").

Using Java, you can create named queries for all query types and store them in a descriptor's DescriptorQueryManager (see Section 119.7.2, "How to Configure Named Queries at the Descriptor Level Using Java").

Table 119-4 summarizes which descriptors support named query configuration.

Table 119-8 Descriptor Support for Named Queries

Descriptor How to Use Oracle JDeveloper How to Configure Named Queries at the Descriptor Level Using TopLink Workbench
How to Configure Named Queries at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS DescriptorFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

For CMP projects, the ejb-jar.xml file stores query lists. You can define the queries in the file, and then read them into Oracle JDeveloper or TopLink Workbench, or define them on the Queries tab and write them to the file. See Section 19.7, "Working with the ejb-xml.File" for more information.

After you create a named query, you can execute it by name and class on the TopLink session (see Section 109.3, "Using Named Queries").

For more information about named queries, see Section 108.8, "Named Queries".

119.7.1 How to Configure Named Queries at the Descriptor Level Using TopLink Workbench

To create a named query, use this procedure

  1. In the Navigator, select a descriptor. Its properties appear in the Editor.

  2. Click the Queries tab in the Editor. The Queries tab appear with three additional tabs.

  3. Click the Named Queries tab in the Queries tab. The Named Queries tab appears.

    Figure 119-6 Queries Tab–Named Queries Subtab

    Description of Figure 119-6 follows
    Description of "Figure 119-6 Queries Tab–Named Queries Subtab"

Use the following information to complete each field on this tab:

Field Description
Queries Lists the existing queries for this descriptor.
  • To create a new query, click Add (see Section 119.7.1.1, "Adding Named Queries").

  • To delete an existing query, select the query and click Delete. TopLink Workbench prompts for confirmation.

  • To rename an existing query, select the query and click Rename. The Rename dialog box appears. Type a new name for the query and click OK.

Query Variety Displays the variety of the currently selected query (see Section 119.7.1.1, "Adding Named Queries").
Quick View Lists the parameters and joined attributes defined for the query.

Clicking on a heading in the Quick View area selects the corresponding subtab. You can also remove parameters or attributes from the Quick View area by selecting the item and clicking Remove.


The Named Queries tab includes the following subtabs:

119.7.1.1 Adding Named Queries

Use this dialog box to create a new named query.

Figure 119-7 Add Named Query Dialog Box

Description of Figure 119-7 follows
Description of "Figure 119-7 Add Named Query Dialog Box"

Use the following information to complete the dialog box and create the named query:

Field Description
Variety For EJB CMP descriptors only, select the variety of query:
    TopLink Named Query Select to create a general purpose TopLink query of the type given by the Type area. You can execute this query by name on the TopLink session passing in the class and arguments (see Section 109.3, "Using Named Queries").
    EJB Finder Select to create a TopLink query of the type given by the Type area for use as the implementation of the EJB CMP finder method of the name you enter. The TopLink runtime executes this query when you call the EJB CMP finder method of the given name.
    TopLink Reserved Finder Select to create a TopLink query of the type given by the Type area for use as the implementation of the TopLink reserved finder method name you select. The TopLink runtime executes this query when you call the EJB CMP finder method of the given name.

For more information, see Section 108.15.1, "Predefined Finders".

    EJB Select Select to create a TopLink query of the type given by the Type area for use as the implementation of the EJB CMP life cycle method ejbSelect. The TopLink runtime executes this query whenever the ejbSelect method is called.
Type Select the type of query:
  • ReadObject (ReadObjectQuery)

  • ReadAll (ReadAllQuery)

  • ReportFoot 1  (ReportQuery)

Note: If Variety is set to TopLink Reserved Finder, you cannot select a query Type.

Name The name of this query.
  • If Variety is set to TopLink Named Query, you can specify any name.

  • If Variety is set to EJB Finder, the name must be prefixed by find.

  • If Variety is set to TopLink Reserved Finder, select from the list of available names that TopLink reserves. For more information, see Section 108.15.1, "Predefined Finders".

  • If Variety is set to EJB Select, the name must be ejbSelect.


Footnote 1 Relational descriptors only.

Enter the necessary information and click OK. TopLink Workbench adds the query to the list of queries in the Named Query tab.

119.7.1.2 Configuring Named Query Type and Parameters

Use this tab to select the query type and add or remove parameters.

Figure 119-8 Named Queries, General Tab

Description of Figure 119-8 follows
Description of "Figure 119-8 Named Queries, General Tab"

Use the following information to complete each field on this tab:

Field Description
Type Select the type of query from the list. You can create any of the following query types:
  • ReadAllQuery

  • ReadObjectQuery

  • ReportQueryFoot 1 

To create other types of query, you must use Java (see Section 119.7.2, "How to Configure Named Queries at the Descriptor Level Using Java").

When you change the type of an existing query, TopLink Workbench preserves any configuration that is common between the old and new type and warns you if changing the type will result in the loss of configuration that is not shared by the new type.

Parameters For queries that take parameters, specify the parameters:
  • To add a new parameter, click Add. The Add Query Parameter dialog box appears. Click Browse to select the type, specify a name, and click OK.

  • To delete an existing parameter, select the parameter and click Remove. TopLink Workbench prompts for confirmation.

  • To modify an existing parameter, select the parameter and click Edit. The Edit Query Parameter dialog box appears. Modify the name and type of the parameter and click OK.

  • To change the order of the parameters, select an existing parameter and click Up or Down.

    Type Select the class of the parameter's type.
    Name Enter the name of the parameter.

Footnote 1 Relational descriptors only.

119.7.1.3 Configuring Named Query Selection Criteria

Use this tab to specify the format of the named query and enter the query string.

Figure 119-9 Named Queries, Selection Criteria Tab

Description of Figure 119-9 follows
Description of "Figure 119-9 Named Queries, Selection Criteria Tab"

Use the following information to complete each field on this tab:

Field Description
Type Specify if query uses a TopLink Expression, SQL, or EJB QL.
Expression or Query String If the Type is SQL or EJB QL, enter the query string (either SQL or EJB QL).

TopLink Workbench does not validate the query string.

See a note that follows this table for information on query syntax.


Note:

Use a combination of an escape character and a double-quote ( \" ) instead of just a double-quote ( " ) when defining your query using SQL or EJB QL. For example:
SELECT OBJECT(employee) FROM Employee employee WHERE employee.name = \"Bob\"

If you fail to do so, the generated Java code would look as follows:

query.setEJBQLString("SELECT OBJECT(employee) FROM Employee employee WHERE employee.name = "Bob"");

The preceding code produces an error at compile time.

If you define your query using the correct syntax, the generated Java code will contain no errors and be similar to the following:

query.setEJBQLString("SELECT OBJECT(employee) FROM Employee employee WHERE employee.name = \"Bob\"");

119.7.1.4 Configuring Read All Query Order

Use this tab to specify how the results of a read all query should be ordered by attribute name.

Figure 119-10 Named Queries, Order Tab

Description of Figure 119-10 follows
Description of "Figure 119-10 Named Queries, Order Tab"

Select one of the following actions:

  • To add a new attribute by which to order query results, click Add. The Add Ordering Attribute dialog box appears. Select the mapped attribute to order by, specify ascending or descending order, and then click OK.

  • To change the order of the order attributes, select an existing attribute and click Up or Down.

  • To modify an existing order attribute's ordering options, select an existing attribute and click Edit.

  • To remove an order attribute, select an existing attribute and click Remove.

119.7.1.5 Configuring Named Query Optimization

You can optimize a named query by configuring batch (ReadAllQuery only) or joining (ReadAllQuery and ReadObjectyQuery) attributes.

For more information on using batch reading, see Optimizing Queries, Section 12.12.9.2, "Reading Case 2: Batch Reading Objects", and Section 109.2.1.9, "Using Batch Reading".

For more information on joining, see Section 108.7.1.5, "Join Reading and Object-Level Read Queries" and Section 109.2.1.10, "Using Join Reading with ObjectLevelReadQuery".

Use this tab to specify batch reading and joining attributes.

Figure 119-11 Named Queries, Optimization Tab

Description of Figure 119-11 follows
Description of "Figure 119-11 Named Queries, Optimization Tab"

Select one of the following actions for Batch Read Attributes (ReadAllQuery only):

  • To add a new batch read attribute, click Add. The Add Batch Read Attribute dialog box appears. Select the mapped attribute and click OK.

  • To change the order of the batch read attributes, select an existing attribute and click Up or Down.

  • To modify an existing batch read attribute's options, select an existing attribute and click Edit.

  • To remove a batch read attribute, select an existing attribute and click Remove.

Select one of the following actions for Joined Attributes (ReadAllQuery and ReadObjectQuery):

  • To add a new joined attribute, click Add. The Add Joined Attribute dialog box appears.

    Figure 119-12 Add Joined Attribute Dialog Box

    Description of Figure 119-12 follows
    Description of "Figure 119-12 Add Joined Attribute Dialog Box"

    Select the mapped attribute. Optionally, enable or disable Allows Null or, for a Collection attribute, Allows None. Click OK.

  • To change the order of the joined attributes, select an existing attribute and click Up or Down.

  • To modify an existing joined attribute's options, select an existing attribute and click Edit.

  • To remove a joined attribute, select an existing attribute and click Remove.

119.7.1.6 Configuring Named Query Attributes

For ReportQuery queries only, you can configure report query functions to apply to one or more attributes.

For more information about report queries, see Section 108.7.5, "Report Query".

Use this tab to configure report query attributes.

Figure 119-13 Named Queries, Attributes Tab

Description of Figure 119-13 follows
Description of "Figure 119-13 Named Queries, Attributes Tab"

Select one of the following actions for Attributes (ReportQuery only):

  • To add a new report query attribute, click Add. The Add Joined Attribute dialog box appears. Continue with Section 119.7.1.6.1, "Adding Report Query Attributes".

  • To change the order of the report query attribute attributes, select an existing attribute and click Up or Down.

  • To modify an existing report query attribute's options, select an existing attribute and click Edit.

  • To remove a report query attribute, select an existing attribute and click Remove.

Note:

You can only choose attributes that are configured with a direct mapping (converters included) or a user-defined query key.
119.7.1.6.1 Adding Report Query Attributes

Use this dialog box to add a report query attribute.

Figure 119-14 Add Report Query Attribute Dialog Box

Description of Figure 119-14 follows
Description of "Figure 119-14 Add Report Query Attribute Dialog Box"

Select the attribute you want in this report query and use the following table to complete the dialog box and add the report query attribute:

Option 'Description
Allows None or Allows Null Use the Allows Null and Allows None options to define an expression with an outer join.

Check the Allows Null option to use the ExpressionBuilder method getAllowingNull.

Check the Allows None option for Collection attributes to use the ExpressionBuilder method anyOfAllowingNone.

For more information, see Section 110.2.7.2, "Using TopLink Expression API for Joins".

Function Select from the list of report query functions that TopLink provides. This function will be applied to the specified attribute. You must select an attribute for all functions, except Count.

Alternatively, you can enter the name of a custom function that you implement in your database. For more information, see Expression method getFunction in the Oracle TopLink API Reference.

Name The name associated with the calculated value. By default, the name is <AttributeName><FunctionName>.

Enter the necessary information and click OK. TopLink Workbench adds the report query attribute to the list of attributes in the Attribute tab.

119.7.1.7 Configuring Named Query Group/Order Options

For ReportQuery queries only, you can configure grouping and ordering attributes.

For more information about report queries, see Section 108.7.5, "Report Query".

Use this tab to specify grouping and ordering attributes.

Figure 119-15 Named Queries, Group/Order Tab

Description of Figure 119-15 follows
Description of "Figure 119-15 Named Queries, Group/Order Tab"

Select one of the following actions for Grouping Attributes (ReportQuery only):

  • To add a new grouping attribute, click Add. The Add Grouping Attribute dialog appears. Select the desired mapped attribute and click OK.

  • To change the order of the grouping attributes, select an existing attribute and click Up or Down.

  • To modify an existing grouping attribute's options, select an existing attribute and click Edit.

  • To remove a grouping attribute, select an existing attribute and click Remove.

Select one of the four following actions for Ordering Attributes (ReportQuery only):

  • To add a new ordering attribute, click Add. The Add Ordering Attribute dialog box appears. Continue with Section 119.7.1.7.1, "Adding Ordering Attributes".

  • To change the order of the ordering attributes, select an existing attribute and click Up or Down.

  • To modify an existing ordering attribute's options, select an existing attribute and click Edit.

  • To remove an ordering attribute, select an existing attribute and click Remove.

119.7.1.7.1 Adding Ordering Attributes

Use this dialog box to add a report query ordering attribute.

Figure 119-16 Add Ordering Attribute Dialog Box

Description of Figure 119-16 follows
Description of "Figure 119-16 Add Ordering Attribute Dialog Box"

Use the following information to complete the fields on the dialog box and add an ordering attribute:

Option 'Description
Selected Attribute Select this option to view a list of the report query attributes you added (see Section 119.7.1.6, "Configuring Named Query Attributes").

Select an attribute and choose its ordering option in the Order field.

New Attribute Select this option to view a list of all class attributes.

Select an attribute and choose its ordering option in the Order field.

Order Select ascending or descending.

Enter the necessary information and click OK. TopLink Workbench adds the report query attribute to the list of attributes in the Attribute tab.

119.7.1.8 Creating an EIS Interaction for a Named Query

For an EIS root descriptor, you can define EIS interactions to invoke methods on an EIS.

You can use TopLink to define an interaction as a named query for read object and read all object queries, as described here. These queries are not called for basic persistence operations (Section 76.5, "Configuring Custom EIS Interactions for Basic Persistence Operations"); you can call these additional queries by name in your application for special purposes.

Use this tab to define an interaction as a named query for read object and read all object queries.

Use the following information to complete each field on the tab:

Field Description
Interaction Type Using TopLink Workbench, you can only use XML Interactions. You cannot change this field.
Function Name Specify the name of the EIS function that this call type (Read Object or Read All) invokes on the EIS.
Input Record Name Specify the name passed to the JCA adapter when creating the input record.
Input Root Element Specify the root element name to use for the input DOM.
Input Arguments Specify the query argument name to map to the interaction field or XPath nodes in the argument record.

For example, if you are using XML records, use this option to map input argument name to the XPath name/first-name.

Output Arguments Specify the result record field or XPath nodes to map the correct nodes in the record used by the descriptor's mappings.

For example, if you are using XML records, use this option to map the output fname to name/first-name.

Output arguments are not required if the interaction returns an XML result that matches the descriptor's mappings.

Input Result Path Use this option if the EIS interaction expects the interaction arguments to be nested in the XML record.

For example, specify arguments, if the arguments were to be nested under the root element exec-find-order, then under an arguments element.

Output Result Path Use this option if the EIS interaction result record contains the XML data that maps to the objects in a nested structure.

For example, specify order, if the results were return under a root element results, then under an order element.

Properties Specify any properties required by your EIS platform. For example, property name operation (from AQPlatform.QUEUE_OPERATION) and property value enqueue (from AQPlatform.ENQUEUE).

119.7.1.9 Configuring Named Query Options

Use this tab to configure additional options for the query.

Figure 119-18 Named Queries, Options Tab

Description of Figure 119-18 follows
Description of "Figure 119-18 Named Queries, Options Tab"

Use the following information to complete each field on the tab:

Field Description
Refresh Identity Map ResultsFootref 2 Refreshes the attributes of the object(s) resulting from the query. If cascading is used, the private parts of the objects will also be refreshed.
Cache StatementFoot 1  Caches the prepared statements. This requires full parameter binding as well (see Bind Parameters).
Bind ParametersFootref 1 By default, TopLink binds all of the query's parameters.

Deselect this option to disable binding.

Cache UsageFoot 2  Selects how TopLink should use the session cache when a query is executed:
  • Use descriptor settings

  • Do not check cache

  • Check cache by exact primary key

  • Check cache by primary key

  • Check cache then database

  • Check cache only

  • Conform results in unit of work

For more information, see the following:

In Memory Query IndirectionFootref 2 Selects how TopLink should handle indirection (lazy loading) when an in-memory or conforming query is executed:
  • Throw indirection exception–if this object uses indirection and indirection has not been triggered, TopLink will throw an exception.

  • Trigger indirection–if this object uses indirection and indirection has not been triggered, TopLink will trigger indirection.

  • Ignore exception return conformed–returns conforming if an untriggered value holder is encountered. That is, you expect results from the database to conform, and an untriggered value holder is taken to mean that the underlying attribute has not changed.

  • Ignore exception return not conformed–returns not conforming if an untriggered value holder is encountered.

For more information, see the following:

Return ChoiceFoot 3  Selects how TopLink should handle ReportQuery results:
  • Result collection–return ReportQuery results as a Collection of ReportQueryResult objects.

  • Single result–return only the first ReportQueryResult object (not wrapped in a Collection or Map). Use this option if you know that the ReportQuery returns only one row.

  • Single value–return only a single value. Use this option if you know that the ReportQuery returns only one row that contains only one attribute.

  • Single attribute–return only a single Collection of values. If the query returns multiple rows, but each row only has a single attribute, this option will return a Collection of values, instead of a Collection of ReportQueryResults.

For more information, see Section 108.5.1, "Collection Query Results".

Retrieve Primary KeysFootref 3 Selects whether or not TopLink retrieves the primary key values within each result. You can use the primary keys to retrieve the real objects.
  • None–do not retrieve primary keys

  • All–retrieve primary keys for each object read;

  • First–return only the first primary key value (in the case of a composite primary key). This can be used if you just want to know if something exists or not, but do not really care about the value.


Footnote 1  For more information, see Section 12.11.5, "How to Use Parameterized SQL (Parameter Binding) and Prepared Statement Caching for Optimization".

Footnote 2 For ReadObjectQuery and ReadAllQuery queries only.

Footnote 3 For ReportQuery queries only.

Click Advanced to configure additional options. See Section 119.7.1.10, "Configuring Named Query Advanced Options".

See Also

Configuring Named Queries at the Descriptor Level

119.7.1.10 Configuring Named Query Advanced Options

To configure additional advanced query options, use this procedure.

  1. From the Named Queries – Options tab, click Advanced. The Advanced Query Options dialog box appears.

    From the Named Queries – Options tab, click Advanced. The Advanced Query Options dialog box appears.

    Figure 119-19 Advanced Query Options Dialog Box

    Description of Figure 119-19 follows
    Description of "Figure 119-19 Advanced Query Options Dialog Box"

  2. Complete each field in the Advanced Query Options dialog box.

Use the following information to enter data in each field and click OK:

Field Description
Maintain Cache Specify whether to use the cache for the query or to build objects directly from the database result. You should only use this option if you are executing a partial object query (see Section 108.7.1.3, "Partial Object Queries"), whose results cannot be cached.

For more information, see Section 108.16.4, "How to Disable the Identity Map Cache Update During a Read Query".

Use Wrapper Policy Specify whether or not the named query will use the wrapper policy configured for this descriptor.

For more information, see Section 119.32, "Configuring Wrapper Policy".

Prepare SQL Once Specify the setShouldPrepare() for the named query. By default, TopLink optimizes queries to generate their SQL only once. You may need to disable this option for certain types of queries that require dynamic SQL based on their arguments, such as the following:
  • Expressions that use equal where the argument value could be null. This may cause problems on databases that require IS NULL, instead of = NULL.

  • Expressions that use in and use parameter binding. This will cause problems as the in values must be bound individually.

Cache Query Results Specify the cacheQueryResults method for the query. The query will only access the database the first time it is executed. Subsequent execution will return exactly the original result.

For more information, see Section 111.13.1, "How to Cache Results in a ReadQuery".

Refresh Remote Identity Map Results Specify the refreshRemoteIdentityMapResult method for the query. TopLink can refresh the attributes of the object(s) resulting from the query. With cascading, TopLink will also refresh the private parts of the object(s).
Exclusive Connection Specify whether or not the named query will use an exclusive connection. You can also configure exclusive connection acquisition at the session level (see Section 89.12, "Configuring Connection Policy".
Pessimistic Locking Specify the specific pessimistic locking policy for the query or use the locking policy from the descriptor.
Distinct State Specify if TopLink prints the DISTINCT clause, if a distinct has been set. The DISTINCT clause allows you to remove duplicates from the result set.
Query Timeout Specify if the query will time out (or abort) after a specified number of seconds.
Maximum Rows Specify if the query will limit the results to a specified number of rows. Use this to option for queries that could return an excessive number of objects.

119.7.2 How to Configure Named Queries at the Descriptor Level Using Java

To configure named queries in Java, use a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods"). Example 119-1 illustrates an amendment method that creates a named query and adds it to the DescriptorQueryManager.

Example 119-1 Creating a Named Query with an Amendment Method

public class EmployeeAmmendmentMethodClass {
....
    // Create named query with Employee as its reference class
    public static void createEmployeeQuery(ClassDescriptor descriptor) {
        ReadObjectQuery query = new ReadObjectQuery(Employee.class);
        ExpressionBuilder emp = query.getExpressionBuilder();
        Expression firstNameExpression =             emp.get("firstName").equal(emp.getParameter("firstName"));
        query.setSelectionCriteria(firstNameExpression);
        query.addArgument("firstName");

        descriptor.getQueryManager().addQuery(
                            "employeeReadByFirstName", query);
    }
}

119.8 Configuring Query Timeout at the Descriptor Level

You can specify how the TopLink runtime handles the duration of queries on a descriptor's reference class. Specifying a query timeout at the descriptor level applies to all queries on the descriptor's reference class. A query timeout ensures that your application does not block forever over a hung or lengthy query that does not return in a timely fashion.

Table 119-4 summarizes which descriptors support query timeout configuration.

Table 119-9 Descriptor Support for Cache Refresh

Descriptor How to Use Oracle JDeveloper How to Configure Query Timeout at the Descriptor Level TopLink Workbench
How to Configure Query Timeout at the Descriptor Level Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS Descriptor

Unsupported.

Unsupported.

Unsupported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

You can also configure a timeout on a per-query basis. For more information, see the following:

119.8.1 How to Configure Query Timeout at the Descriptor Level TopLink Workbench

To configure how TopLink handles the duration of queries to this descriptor, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Queries tab. The Queries tab appears.

  3. Click the Settings tab. The Settings tab appears.

    Figure 119-20 Descriptor Queries Settings Tab, Query Timeout Options

    Description of Figure 119-20 follows
    Description of "Figure 119-20 Descriptor Queries Settings Tab, Query Timeout Options"

Use the following table to enter data in the fields on the descriptor's Settings tab to specify how TopLink handles query duration:

Field Description
Default Timeout TopLink throws a DatabaseException if a query on this descriptor does not return within the timeout period you configure on the parent descriptor. If there is no parent descriptor, the query timeout defaults to No Timeout.
No Timeout TopLink blocks until a query on this descriptor returns.
Timeout Enter the timeout period in seconds. TopLink throws a DatabaseException if a query on this descriptor does not return within this time.

119.8.2 How to Configure Query Timeout at the Descriptor Level Java

Use DescriptorQueryManager method setQueryTimeout passing in the timeout value as a number of milliseconds.

119.9 Configuring Cache Refreshing

By default, TopLink caches objects read from a data source (see Chapter 102, "Introduction to Cache"). Subsequent queries for these objects will access the cache and thus improve performance by reducing data source access and avoiding the cost of rebuilding object's and their relationships. Even if a query, such as a read-all query, accesses the data source, if the objects corresponding to the records returned are in the cache, TopLink will use the cache objects.

This can lead to stale data in the application. Although using an appropriate locking policy (see Section 119.26, "Configuring Locking Policy") is the only way to ensure that stale or conflicting data does not get committed to the data source, sometimes certain data in the application changes so frequently that it is desirable to always refresh the data, instead of only refreshing the data when a conflict is detected.

You can specify how the TopLink runtime handles cache refreshing for all queries on a descriptor's reference class.

Table 119-4 summarizes which descriptors support query cache refresh configuration.

Table 119-10 Descriptor Support for Query Cache Refresh

Descriptor How to Use Oracle JDeveloper How to Configure Cache Refreshing Using TopLink Workbench
How to Configure Cache Refreshing Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS DescriptorFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

Configuring descriptor-level cache refresh may affect performance. As an alternative, consider configuring the following:

For more information, see Section 12.10, "Optimizing Cache".

119.9.1 How to Configure Cache Refreshing Using TopLink Workbench

To configure how TopLink refreshes the cache for queries to this descriptor, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Queries tab. The Queries tab appears.

  3. Click the Settings tab. The Settings tab appears.

    Figure 119-21 Descriptor Queries Settings Tab, Cache Refreshing Options

    Description of Figure 119-21 follows
    Description of "Figure 119-21 Descriptor Queries Settings Tab, Cache Refreshing Options"

Use the following table to enter data in the fields on the descriptor's Settings tab to specify how TopLink will refresh the cache for queries:

Field Description
Always Refresh Refreshes the cache on all queries.

Avoids stale data by ensuring that any query that accesses the data source will refresh the resulting objects in the cache. This has no effect on queries that get a cache hit and never access the data source, such as read-object primary key queries or in-memory queries.

Configuring descriptor level cache refresh may affect performance. As an alternative, consider configuring:

Only Refresh If Newer Version Refreshes the cache only if the object in the database is newer than the object in the cache (as determined by the Optimistic Locking field). See Section 119.26, "Configuring Locking Policy" for more information.

Improves performance by avoiding unnecessary refreshing of an object if its version matches the data source version. This option does not cause refreshing on its own: you must use it in combination with Always Refresh, query refreshing (see Section 108.16.5, "How to Refresh the Cache"), or cache expiration (see Section 119.16, "Configuring Cache Expiration at the Descriptor Level").

Disable Cache Hits When selected, TopLink bypasses the cache and goes to the database for read object queries based on primary key. Using this option in conjunction with Always Refresh ensures that TopLink always goes to the database.

This option ensures that all queries including read-object primary key queries will always access the data source. This option does not cause refreshing on its own: you must use it in combination with Always Refresh.

This option can cause a serious performance issue: avoid whenever possible.


Caution:

Use the Always Refresh and Disable Cache Hits properties with caution as they may lead to poor performance. As an alternative, consider configuring cache refresh on a query-by-query basis (see Section 108.16.5, "How to Refresh the Cache") or configuring cache expiration (see Section 119.16, "Configuring Cache Expiration at the Descriptor Level"). For more information about cache performance, see Section 12.10, "Optimizing Cache".

119.9.2 How to Configure Cache Refreshing Using Java

Configure cache refresh options using the following ClassDescriptor methods:

  • setShouldAlwaysRefreshCache

  • setShouldAlwaysRefreshCacheOnRemote

  • setShouldDisableCacheHits

  • setShouldDisableCacheHitsOnRemote

  • setShouldOnlyRefreshCacheIfNewerVersion

Use these methods in a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods"), as Example 119-2 illustrates.

Example 119-2 Configuring Remote Refreshing

public void addToDescriptor(ClassDescriptor descriptor) {
    descriptor.setShouldRefreshCacheOnRemote(true);
    descriptor.setShouldDisableCacheHitsOnRemote(true);
}

119.10 Configuring Query Keys

A query key is a schema-independent alias for a database field name. For example, consider a class Employee with attribute firstName mapped directly to a database field F_NAME in database table EMPLOYEE. Without a query key, when you create a query or expression that involves Employee attribute firstName, you must use the database management system-specific field name F_NAME. This makes it more difficult to build a query and ties the query to the schema. With a query key, you can refer to this field using a schema-independent alias, such as firstName.

Table 119-11 summarizes which descriptors support query keys.

Table 119-11 Descriptor Support for Query Keys

Descriptor How to Use Oracle JDeveloper How to Configure Query Keys Using TopLink Workbench
How to Configure Query Keys Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported Unsupported Unsupported

Using query keys offers the following advantages:

  • Enhances code readability in TopLink expressions and simplifies expression development. You can compose expressions entirely within the context of your object model.

  • Increases portability by making code independent of the database schema. If you rename a field in your schema, you can redefine the query key without changing any code that uses it.

  • Query keys used with interface descriptors allow the implementor descriptor's tables to have different field names.

Query keys are automatically generated for all mapped attributes. The name of the query key is the name of the class attribute specified in your object model.

For information on how to use query keys in queries and expressions, see Section 108.2.7, "Query Keys".

When query keys are generated and how you can add or modify query keys depends on the type of mapping or descriptor involved:

Direct Mappings

TopLink Workbench automatically generates query keys for all direct mappings at the time you create the mapping.

TopLink Workbench provides support for adding or modifying query keys for simple unmapped attributes that could be mapped by a direct mapping: for example, the version field used for optimistic locking or the type field used for inheritance. You cannot modify or remove automatically generated query keys.

Relationship Mappings

TopLink automatically generates query keys for all relationship mappings at run time.

For example, if you have a class Customer with attribute orders mapped in a one-to-many relationship to class PurchaseOrders, then the TopLink runtime will generate a query key named orders for this Customer attribute.

Neither Oracle JDeveloper nor TopLink Workbench currently support adding or modifying the query keys for relationship mappings. If you must add or modify such a query key, you must do so in Java code, using a descriptor amendment method.

Interface Descriptors

Interface descriptors (see Section 22.2.1.3, "Creating Relational Interface Descriptors") define only the query keys that are shared among their implementors. In the descriptor for an interface, only the name of the query key is specified.

TopLink Workbench provides support for choosing the implementors of an interface that share at least one common automatically generated query key (see Section 119.11, "Configuring Interface Query Keys").

119.10.1 How to Configure Query Keys Using TopLink Workbench

To add query keys to simple unmapped fields and to view the query keys automatically generated for directly mapped attributes, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Query Keys tab in the Editor.

    Figure 119-22 Queries, Query Keys Tab

    Description of Figure 119-22 follows
    Description of "Figure 119-22 Queries, Query Keys Tab"

To add a new query key, click Add.

To delete an existing query key, select the query key and click Remove.

To rename an existing query key, select the query key and click Rename.

Use the Field list to select the field in the table associated with the query key.

119.10.2 How to Configure Query Keys Using Java

To manually create a relationship query key, implement a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") that uses one of the following ClassDescriptor methods to register the query keys:

  • addQueryKey–specify a query key using an instance of QueryKey such as DirectQueryKey, DirectCollectionQueryKey, ManyToManyQueryKey, OneToManyQueryKey, or OneToOneQueryKey.

  • addDirectQueryKey–add a query key that maps directly to the given database field.

  • addAbstractQueryKey–add an abstract query key to an interface descriptor. Any implementors of that interface must define the query key defined by this abstract query key.

Example 119-3, Example 119-4, and Example 119-5 illustrate how to define a query key in Java code.

Example 119-3 Defining a Query Key

// Add a query key for the foreign key field using the direct method
descriptor.addDirectQueryKey("managerId", "MANAGER_ID");

// The same query key can also be added through the addQueryKey method
DirectQueryKey directQueryKey = new DirectQueryKey();
directQueryKey.setName("managerId");
directQueryKey.setFieldName("MANAGER_ID");
descriptor.addQueryKey(directQueryKey);

// Add a one-to-one query key for the large project of which the
// employee is a leader (this assumes only one project)
OneToOneQueryKey projectQueryKey = new OneToOneQueryKey();
projectQueryKey.setName("managedLargeProject");
projectQueryKey.setReferenceClass(LargeProject.class);
ExpressionBuilder builder = new ExpressionBuilder();
projectQueryKey.setJoinCriteria(builder.getField(
    "PROJECT.LEADER_ID").equal(builder.getParameter("EMPLOYEE.EMP_ID")));
descriptor.addQueryKey(projectQueryKey);

Example 119-4 Defining a One-to-Many Query Key

// Add a one-to-many query key for the projects where the employee
// manages multiple projects 
OneToManyQueryKey projectsQueryKey = new OneToManyQueryKey();
projectsQueryKey.setName("managedProjects");
projectsQueryKey.setReferenceClass(Project.class);
ExpressionBuilder builder = new ExpressionBuilder();
projectsQueryKey.setJoinCriteria(builder.getField(
    "PROJECT.LEADER_ID").equal(builder.getParameter("EMPLOYEE.EMP_ID")));
descriptor.addQueryKey(projectsQueryKey);

Example 119-5 Defining a Many-to-Many Query Key

// Add a many-to-many query key to an employee project that uses a join table
ManyToManyQueryKey projectsQueryKey = new ManyToManyQueryKey();
projectsQueryKey.setName("projects");
projectsQueryKey.setReferenceClass(Project.class);
ExpressionBuilder builder = new ExpressionBuilder();
projectsQueryKey.setJoinCriteria(
    builder.getTable("EMP_PROJ").getField("EMP_ID").equal(
    builder.getParameter("EMPLOYEE.EMP_ID").and(
    builder.getTable("EMP_PROJ").getField("PROJ_ID").equal(
    builder.getField("PROJECT.PROJ_ID")));
descriptor.addQueryKey(projectsQueryKey);

Example 119-6 illustrates how to implement a Descriptor amendment method to define a one-to-one query key. In this example, the object model for the Address class does not include a reference to its owner, an Employee object. You can amend the Address class descriptor to add a query key named owner to make up for this deficiency. At run time, you can compose expressions that select Address objects based on this owner query key.

Example 119-6 Defining a One-to-One Query Key with an Amendment Method

// Static amendment method in Address class, addresses do not know 
// their owners in the object model, however you can still
// query on their owner if a user-defined query key is defined
public static void addToDescriptor(Descriptor descriptor) {
    OneToOneQueryKey ownerQueryKey = new OneToOneQueryKey();
    ownerQueryKey.setName("owner");
    ownerQueryKey.setReferenceClass(Employee.class);
    ExpressionBuilder builder = new ExpressionBuilder();
    ownerQueryKey.setJoinCriteria(
        builder.getField("EMPLOYEE.ADDRESS_ID").equal(
        builder.getParameter("ADDRESS.ADDRESS_ID")));
    descriptor.addQueryKey(ownerQueryKey);
}

119.11 Configuring Interface Query Keys

A query key is a schema independent alias for a database field name. For more information about query keys, see Section 119.10, "Configuring Query Keys".

Interface descriptors (see Section 22.2.1.3, "Creating Relational Interface Descriptors") are defined only with query keys that are shared among their implementors. In the descriptor for an interface, only the name of the query key is specified.

In each implementor descriptor, the key must be defined with the appropriate field from one of the implementor descriptor's tables.

This allows queries and relationship mappings to be defined on the interface using the query key names.

Interface query keys are supported in relational database projects only.

Table 119-11 summarizes which descriptors support interface query keys.

Table 119-12 Descriptor Support for Interface Query Keys

Descriptor How to Use Oracle JDeveloper How to Configure Interface Query Keys Using TopLink Workbench
How to Configure Interface Query Keys Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported Unsupported Unsupported

Consider an Employee that contains a contact of type Contact. The Contact class is an interface with two implementors: Phone and Email. The Phone class has attributes id and number. The Email class has attributes id and address. Figure 119-23 illustrates the generated keys:

Figure 119-23 Automatically Generated Query Keys for Phone and Email

Description of Figure 119-23 follows
Description of "Figure 119-23 Automatically Generated Query Keys for Phone and Email "

Both classes have an attribute, id, that is directly mapped to fields that have different names. However, a query key is generated for this attribute. For the Contact interface descriptor, you must indicate that the id query key must be defined for each of the implementors.

If either of the implementor classes did not have the id query key defined, Oracle JDeveloper and TopLink Workbench would flag that descriptor as deficient.

Now that a descriptor with a commonly shared query key has been defined for Contact, you can use it as the reference class for a variable one-to-one mapping (see Section 111.8, "Using Queries on Variable One-to-One Mappings").

For example, you can now create a variable one-to-one mapping for the contact attribute of Employee. When you edit the foreign key field information for the mapping, you must match the Employee descriptor's tables to query keys from the Contact interface descriptor.

119.11.1 How to Configure Interface Query Keys Using TopLink Workbench

To choose the implementors of an interface that share at least one common automatically generated query key, use this procedure.

  1. Select an interface descriptor in the Navigator. Its properties appear in the Editor.

    Figure 119-24 Interface Descriptor Editor Window

    Description of Figure 119-24 follows
    Description of "Figure 119-24 Interface Descriptor Editor Window"

To choose an implementor of the selected interface that shares at least one common query key, click Add.

To remove an implementor of the selected interface, select the implementor and click Remove.

119.11.2 How to Configure Interface Query Keys Using Java

Example 119-7 shows how to define the Contact interface and Email and Phone implementors in Java.

Example 119-7 Defining Interface Query Keys

Descriptor contactInterfaceDescriptor = new Descriptor();
contactInterfaceDescriptor.setJavaInterface(Contact.class);
contactInterfaceDescriptor.addAbstractQueryKey("id");

Descriptor emailClassDescriptor = new Descriptor();
emailClassDescriptor.setJavaClass(Email.class);
emailClassDescriptor.addDirectQueryKey("id", "E_ID");
emailClassDescriptor.getInterfacePolicy().addParentInterface(Contact.class);
emailClassDescriptor.setTableName("INT_EML");
emailClassDescriptor.setPrimaryKeyFieldName("E_ID");
emailClassDescriptor.setSequenceNumberName("SEQ");
emailClassDescriptor.setSequenceNumberFieldName("E_ID");
emailClassDescriptor.addDirectMapping("emailID", "E_ID");
emailClassDescriptor.addDirectMapping("address", "ADDR");

Descriptor phoneClassDescriptor = new Descriptor();
phoneClassDescriptor.setJavaClass(Phone.class);
phoneClassDescriptor.getInterfacePolicy().addParentInterface(Contact.class);
phoneClassDescriptor.addDirectQueryKey("id", "P_ID");
phoneClassDescriptor.setTableName("INT_PHN");
phoneClassDescriptor.setPrimaryKeyFieldName("P_ID");
phoneClassDescriptor.setSequenceNumberName("SEQ");
phoneClassDescriptor.setSequenceNumberFieldName("P_ID");
phoneClassDescriptor.addDirectMapping("phoneID", "P_ID");
phoneClassDescriptor.addDirectMapping("number", "P_NUM");

119.12 Configuring Cache Type and Size at the Descriptor Level

The TopLink cache is an in-memory repository that stores recently read or written objects based on class and primary key values. TopLink uses the cache to do the following:

  • improve performance by holding recently read or written objects and accessing them in-memory to minimize database access;

  • manage locking and isolation level;

  • manage object identity.

Table 119-13 summarizes which descriptors support identity map configuration.

Table 119-13 Descriptor Support for Identity Map

Descriptor How to Use Oracle JDeveloper How to Configure Cache Type and Size at the Descriptor Level Using TopLink Workbench
How to Configure Cache Type and Size at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

This configuration overrides the default identity map configuration defined at the project level (see Section 117.10, "Configuring Cache Type and Size at the Project Level").

For detailed information on caching and object identity, and the recommended settings to maximize TopLink performance, see to Section 102.2.1, "Cache Type and Object Identity".

For more information about the cache, see Chapter 102, "Introduction to Cache".

119.12.1 How to Configure Cache Type and Size at the Descriptor Level Using TopLink Workbench

To specify the identity map information for a descriptor, use this procedure:

  1. Select the descriptor in the Navigator.

  2. Select the Caching tab in the Editor. The Caching tab appears.

    Figure 119-25 Caching Tab, Identity Map Options

    Description of Figure 119-25 follows
    Description of "Figure 119-25 Caching Tab, Identity Map Options"

Use the following table to enter data in following fields on the Caching tab:

Field Description
TypeFoot 1  Use the Type list to choose the identity map as follows:

For more information, see Section 102.2.1, "Cache Type and Object Identity".

Changing the project's default identity map does not affect descriptors that already exist in the project.

SizeFootref 1 Specify the size of the cache as follows:
  • When using Weak with Soft Subcache or Weak with Hard Subcache, the size is the size of the subcache.

  • When using Full or Weak, the size indicates the starting size of the identity map.

Default When you enter a cache size, the Default check box is cleared. To reset the size to the default for the selected cache type, check the Default check box.

Footnote 1 If a descriptor is a child in an inheritance hierarchy, TopLink makes this field read only and displays the options from the parent root descriptor. For more information, see Section 16.2.3.3, "Inheritance".

119.12.2 How to Configure Cache Type and Size at the Descriptor Level Using Java

Use one of the following ClassDescriptor methods to configure the descriptor to use the appropriate type of identity map:

  • useFullIdentitMap

  • useWeakIdentityMap

  • useSoftIdentityMap

  • useSoftCacheWeakIdentityMap

  • useHardCacheWeakIdentityMap

  • useNoIdentityMap

Use the ClassDescriptor method setIdentityMapSize to configure the size of the identity map.

119.13 Configuring Cache Isolation at the Descriptor Level

If you plan to use isolated sessions (see Section 102.2.7, "Cache Isolation"), you must configure descriptors as isolated for any object that you want confined to an isolated session cache.

Configuring a descriptor to be isolated means that TopLink will not store the object in the shared session cache and the object will not be shared across client sessions. Each client will have their own object read directly from the database. Objects in an isolated client session cache can reference objects in their parent server session's shared session cache, but no objects in the shared session cache can reference objects in an isolated client session cache. Isolation is required when using Oracle Database Virtual Private Database (VPD) support or database user-based read security. Isolation can also be used if caching is not desired across client sessions.

Table 119-13 summarizes which descriptors support cache isolation configuration.

Table 119-14 Descriptor Support for Cache Isolation Map

Descriptor How to Use Oracle JDeveloper How to Configure Cache Isolation at the Descriptor Level Using TopLink Workbench
How to Configure Cache Isolation at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

This configuration overrides the default cache isolation configuration defined at the project level (see Section 117.11, "Configuring Cache Isolation at the Project Level").

Note:

If you configure a descriptor as isolated, it cannot participate in a coordinated cache (see Section 119.15, "Configuring Cache Coordination Change Propagation at the Descriptor Level").

119.13.1 How to Configure Cache Isolation at the Descriptor Level Using TopLink Workbench

To specify the cache isolation options, use this procedure:

  1. Select the descriptor in the Navigator.

  2. Select the Caching tab in the Editor. The Caching tab appears.

    Figure 119-26 Caching Tab, Isolation Options

    Description of Figure 119-26 follows
    Description of "Figure 119-26 Caching Tab, Isolation Options"

Use the Isolation list to choose one of the following:

  • Isolated–if you want all objects confined to an isolated client session cache. For more information, see Section 102.2.7, "Cache Isolation".

  • Shared–if you want all objects visible in the shared session cache (default).

119.13.2 How to Configure Cache Isolation at the Descriptor Level Using Java

To specify that a class is isolated, use a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") to call ClassDescriptor method setIsIsolated, passing in a boolean of true.

119.14 Configuring Unit of Work Cache Isolation at the Descriptor Level

Use this policy to determine how a unit of work uses a session cache for a specific class. Table 119-15 lists the unit of work cache isolation options.

Table 119-15 Unit of Work Cache Isolation Options

Option Description

Using the Session Cache After the Transaction

USE_SESSION_CACHE_AFTER_TRANSACTIONObjects built from new data accessed after a unit of work early transaction are stored in the session cache.

This options is the most efficient as it allows the cache to be used after an early transaction.

Isolating New Data After the Transaction

ISOLATE_NEW_DATA_AFTER_TRANSACTION (default) Objects built from new data accessed after a unit of work early transaction are only stored in the unit of work.

This still allows previously cached objects to be accessed in the unit of work after an early transaction, while ensuring that uncommitted data will never be put in the session cache by storing any object built from new data only in the unit of work

Isolating the Cache after the Transaction

ISOLATE_CACHE_AFTER_TRANSACTIONAfter a unit of work early transaction the session cache is no longer used for this class. Objects are directly built from the database data and only stored in the unit of work, even if previously cached.

Note: This option may affect performance because you are bypassing the session cache after an early transaction.

Always Isolating the Cache

ISOLATE_CACHE_ALWAYSThe session cache will never be used for the class. Objects are directly built from the database data and only stored in the unit of work. New objects and changes will never be merged into the session cache.

Note: This option my affect performance because you are bypassing the session cache. However if this class is isolated or pessimistic locked and always accessed in a transaction, this can avoid having to build two copies of the object.


Most of these options apply only to a unit of work in an early transaction, such as the following:

  • A unit of work that was flushed (write changes).

  • Issued a modify query.

  • Acquired a pessimistic lock.

119.14.1 How to Configure Unit of Work Cache Isolation at the Descriptor Level Using Java

To specify that a class is isolated, use a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") to call ClassDescriptor method setUnitOfWorkCacheIsolationLevel.

119.15 Configuring Cache Coordination Change Propagation at the Descriptor Level

If you plan to use a coordinated cache (see Section 102.3, "Cache Coordination"), you can configure how, and under what conditions, a coordinated cache propagates changes for a given descriptor.

Table 119-13 summarizes which descriptors support cache isolation configuration.

Table 119-16 Descriptor Support for Cache Coordination Change Propagation Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Cache Coordination Change Propagation at the Descriptor Level Using TopLink Workbench
How to Configure Cache Coordination Change Propagation at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

This configuration overrides the default cache coordination change propagation configuration defined at the project level (see Section 117.12, "Configuring Cache Coordination Change Propagation at the Project Level").

To complete your coordinated cache configuration, see Chapter 103, "Configuring a Coordinated Cache".

Note:

If you configure a descriptor as isolated (see Section 119.13, "Configuring Cache Isolation at the Descriptor Level"), it cannot participate in a coordinated cache.

119.15.1 How to Configure Cache Coordination Change Propagation at the Descriptor Level Using TopLink Workbench

To specify the coordinated cache change propagation options, use this procedure:

  1. Select the descriptor in the Navigator.

  2. Select the Caching tab in the Editor. The Caching tab appears.

    Figure 119-27 Caching Tab, Coordination Options

    Description of Figure 119-27 follows
    Description of "Figure 119-27 Caching Tab, Coordination Options"

Use the following information to enter data in the Coordination field:

Coordination Option Description When to Use
None For both existing and new instances, do not propagate a change notification. Infrequently read or changed objects.
Synchronize Changes For an existing instance, propagate a change notification that contains each changed attribute.

For a new instance, propagate an object creation (along with all the new instance's attributes) only if the new instance is related to other existing objects that are also configured with this change propagation option.

Frequently read or changed objects that contain few attributes or in cases where only a few attributes are frequently changed.

Objects that have many or complex relationships.

Synchronize Changes and New Objects For an existing instance, propagate a change notification that contains each changed attribute.

For a new instance, propagate an object creation (along with all the new instance's attributes).

Frequently read or changed objects that contain few attributes or in cases where only a few attributes are frequently changed.

Objects that have few or simple relationships.

Invalidate Changed Objects For an existing instance, propagate an object invalidation that marks the object as invalid in all other sessions. This tells other sessions that they must update their cache from the data source the next time this object is read.

For a new instance, no change notification is propagated.

Frequently read or changed objects that contain many attributes in cases where many of the attributes are frequently changed.

119.15.2 How to Configure Cache Coordination Change Propagation at the Descriptor Level Using Java

Use a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") to invoke ClassDescriptor method setCacheSynchronizationType passing in one of the following parameters:

  • ClassDescriptor.DO_NOT_SEND_CHANGES

  • ClassDescriptor.SEND_OBJECT_CHANGES

  • ClassDescriptor.SEND_NEW_OBJECTS_WITH_CHANGES

  • ClassDescriptor.INVALIDATE_CHANGED_OBJECTS

119.16 Configuring Cache Expiration at the Descriptor Level

By default, objects remain in the cache until they are explicitly deleted (see Section 114.7, "Deleting Objects") or garbage-collected when using a weak identity map (see Section 117.11, "Configuring Cache Isolation at the Project Level"). Alternatively, you can configure an object with a CacheInvalidationPolicy that allows you to specify, either automatically or manually, that an object is invalid: when any query attempts to read an invalid object, TopLink will go to the data source for the most up-to-date version of that object and update the cache with this information.

Using cache invalidation ensures that your application does not use stale data. It provides a better performing alternative to always refreshing (see Section 119.9, "Configuring Cache Refreshing").

Table 119-17 summarizes which descriptors support a cache invalidation policy.

Table 119-17 Descriptor Support for Cache Invalidation Policy

Descriptor How to Use Oracle JDeveloper How to Configure Cache Expiration at the Descriptor Level Using TopLink Workbench
How to Configure Cache Expiration at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

You can override the project-level cache invalidation configuration (see Section 117.13, "Configuring Cache Expiration at the Project Level") by defining cache invalidation at the descriptor or query level (see Section 111.13.2, "How to Configure Cache Expiration at the Query Level").

You can customize how TopLink communicates the fact that an object has been declared invalid to improve efficiency, if you are using a coordinated cache. For more information, see Section 119.15, "Configuring Cache Coordination Change Propagation at the Descriptor Level".

For more information, see Section 102.2.5, "Cache Invalidation".

119.16.1 How to Configure Cache Expiration at the Descriptor Level Using TopLink Workbench

To specify the cache invalidation information for a descriptor, use this procedure:

  1. Select the descriptor in the Navigator.

  2. Select the Caching tab in the Editor. The Caching tab appears.

    Figure 119-28 Caching Tab, Expiration Options

    Description of Figure 119-28 follows
    Description of "Figure 119-28 Caching Tab, Expiration Options"

Use this table to enter data in the following fields on the Caching tab to specify the cache invalidation policy for the descriptors.

Field Description
Project Default Use the project's cache expiration options for this descriptor. See Section 117.13, "Configuring Cache Expiration at the Project Level" for more information.
No Expiry Specify that objects in the cache do not expire.
Time to Live Expiry Specify that objects in the cache will expire after a specified amount of time. Use the Expire After field to indicate the time (in milliseconds) after which the objects will expire.
Daily Expiry Specify that objects in the cache will expire at a specific time each day. Use the Expire At field to indicate the exact time to the second (using a 24-hour clock) at which the objects will expire.
Update Read Time on Update Specify if TopLink should reset the cached object's expiry time after the TopLink successfully updates the object.

Note:

These options apply per descriptor. See Section 117.13, "Configuring Cache Expiration at the Project Level" for information on configuring project-level options.

119.16.2 How to Configure Cache Expiration at the Descriptor Level Using Java

Use ClassDescriptor method setCacheInvalidationPolicy to set an appropriate instance of CacheInvalidationPolicy.

119.17 Configuring Cache Existence Checking at the Descriptor Level

When TopLink writes an object to the database, TopLink runs an existence check to determine whether to perform an insert or an update.

By default, TopLink checks against the cache. Oracle recommends that you use this default existence check option for most applications. Checking the database for existence can cause a performance bottleneck in your application.

Table 119-18 summarizes which descriptors support existence checking.

Table 119-18 Descriptor Support for Existence Checking

Descriptor How to Use Oracle JDeveloper How to Configure Cache Existence Checking at the Descriptor Level Using TopLink Workbench
How to Configure Cache Existence Checking at the Descriptor Level Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

You can configure existence checking at the descriptor level to override the project level configuration (see Section 117.7, "Configuring Existence Checking at the Project Level").

For more information see the following:

119.17.1 How to Configure Cache Existence Checking at the Descriptor Level Using TopLink Workbench

To specify the existence checking information for a descriptor, use this procedure:

  1. Select the descriptor in the Navigator.

  2. Select the Caching tab in the Editor. The Caching tab appears.

    Figure 119-29 Caching Tab, Existence Checking Options

    Description of Figure 119-29 follows
    Description of "Figure 119-29 Caching Tab, Existence Checking Options"

Use this table to enter data in the following fields of the tab to specify the existence checking options for newly created descriptors:

Field Description
Check Cache Check the session cache. If the object is not in the cache, assume that the object does not exist (do an insert). If the object is in the cache, assume that the object exists (do an update). Oracle recommends using this option for most applications.
Check Cache then Database If an object is not in the cache, query the database to determine if the object exists. If the object exists, do an update. Otherwise, do an insert. Selecting this option may negatively impact performance. For more information, see Section 115.1.3.1, "Using Check Database".
Assume Existence Always assume objects exist: always do an update (never do an insert). For more information, see Section 115.1.3.2, "Using Assume Existence".
Assume Non-Existence Always assume objects do not exist: always do an insert (never do an update). For more information, see Section 115.1.3.3, "Using Assume Nonexistence".

119.17.2 How to Configure Cache Existence Checking at the Descriptor Level Using Java

To configure existence checking at the descriptor level using Java, use ClassDescriptor method getQueryManager to acquire the DescriptorQueryManager from the descriptor and then use one of the following DescriptorQueryManager methods (see Example 119-8):

  • checkCacheForDoesExist–check the session cache. If the object is not in the cache, assume that the object does not exist (do an insert). If the object is in the cache, assume that the object exists (do an update). Oracle recommends using this option for most applications.

  • checkDatabaseForDoesExist–if an object is not in the cache, query the database to determine if the object exists. If the object exists, do an update. Otherwise, do an insert. Selecting this option may negatively impact performance. For more information, see Section 115.1.3.1, "Using Check Database".

  • assumeExistenceForDoesExist–always assume objects exist: always do an update (never do an insert). For more information, see Section 115.1.3.2, "Using Assume Existence".

  • assumeNonExistenceForDoesExist–always assume objects do not exist: always do an insert (never do an update). For more information, see Section 115.1.3.3, "Using Assume Nonexistence".

Example 119-8 Configuring Existence Checking Using Java

descriptor.getQueryManager().checkCacehForDoesExist();

119.18 Configuring a Descriptor with EJB CMP and BMP Information

If your project uses EJB CMP or BMP (see Section 117.5, "Configuring Persistence Type"), you can use descriptors to describe the characteristics of entity beans with container-managed or bean-managed persistence.

Table 119-19 summarizes which descriptors support EJB information.

Table 119-19 Descriptor Support for EJB Information

Descriptor How to Use Oracle JDeveloper How to Configure a Descriptor with EJB CMP and BMP Information Using TopLink Workbench
How to Configure a Descriptor with EJB CMP and BMP Information Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Unsupported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

When mapping enterprise beans, you create a descriptor for the bean class; you do not create a descriptor for the local interface, remote interface, home class, or primary key class.

When using TopLink Workbench, you must define the project with the correct entity bean type (such as container-managed or bean-managed persistence) and import the ejb-jar.xml file for the beans into the TopLink Workbench project.

For CMP projects, the ejb-jar.xml file defines the bean's attributes to be mapped. A descriptor for an entity bean container-managed persistence contains a CMP policy used to configure CMP-specific options.

For more information, see Section 16.2.3, "Descriptors and CMP and BMP".

119.18.1 How to Configure a Descriptor with EJB CMP and BMP Information Using TopLink Workbench

To configure a descriptor with EJB information, use this procedure:

  1. In the Navigator, select a relational descriptor.

  2. EJB Descriptor button.
    Click EJB Descriptor on the mapping toolbar.

    An EJB Info tab is added to the descriptor.

    To remove the EJB information for the selected descriptor, click EJB Descriptor again.

    The EJB Info tab is removed from the descriptor.

  3. Click the EJB Info tab in the Editor

    Figure 119-30 EJB Info Tab

    Description of Figure 119-30 follows
    Description of "Figure 119-30 EJB Info Tab"

Use the following information to enter data in each field on the tab:

Field Description
EJB Name Enter the bean's base name. This is specified in the <ejb-name> element of the ejb-jar.xml file and is for display only.
Primary Key Class Enter the primary key. This is specified in the <prim-key-class> element of the ejb-jar.xml file and is for display only.
Unknown Primary Key Class Check this option if you choose not to specify the primary key class or the primary key fields for an entity bean with container managed persistence.

For example, select this field if the entity bean does not have a natural primary key or you want the deployer to select the primary key fields at deployment time. For more information, see Section 8.9.2, "How to Configure EJB CMP Unknown Primary Key Class Support".

Local Interface Enter the local interface. This is specified in the <local> element of the ejb-jar.xml file and is for display only.
Local Home Interface Enter the local home interface. This is specified in the <local-home> element of the ejb-jar.xml file and is for display only.
Remote Interface Enter the remote interface. This is specified in the <remote> element of the ejb-jar.xml file and is for display only.
Remote Home Interface Enter the remote interface. This is specified in the <home> element of the ejb-jar.xml file and is for display only.
Change Deferral Use these options to specify how TopLink updates the database for this EJB descriptor.
    Defer All Changes Specify not to send changes to the database until the JTA transaction is committed. This is the default TopLink behavior. This is the most efficient option that results in the least amount of data source interaction.
    Defer Updates Only Specify to send changes to the database immediately after any insert or delete operation, but do not send changes to the data source for update operations until the JTA transaction is committed.

Select this option for backwards compatibility with some EJB containers, such as OC4J. For more information, see Section 16.2.3.1, "Nondeferred Changes").

Use this option with caution as it will require the data source transaction and locks to be held longer and may cause referential integrity issues.

    Defer None Specify to send all changes to the database immediately. This is the least efficient option that generates the greatest amount of data source interaction.

Select this option for backwards compatibility with some EJB containers, such as OC4J. For more information, see Section 16.2.3.1, "Nondeferred Changes").

    Insert New Objects After Specify to send new object insert changes to the database after bean life cycle method ejbCreate (default) or ejbPostCreate. This is only relevant when not deferring changes (see Section 119.30, "Configuring Change Policy").

If non-null foreign key constraints cannot be satisfied when the insert is performed after ejbCreate, you may consider configuring TopLink CMP to do the insert after ejbPostCreate, if supported by your container. For more information, see Section 16.2.3.2, "Creating a New Entity Bean and ejbCreate / ejbPostCreate Methods".


119.18.2 How to Configure a Descriptor with EJB CMP and BMP Information Using Java

Using Java code, you can use descriptors to describe the characteristics of entity beans with container-managed (see Section 119.18.2.1, "Configuring CMP Information") or bean-managed (see Section 119.18.2.2, "Configuring BMP Information") persistence.

119.18.2.1 Configuring CMP Information

To configure CMP-specific information on a descriptor, define a CMPPolicy:

descriptor.setCMPPolicy(new CMPPolicy());

You can use the following CMPPolicy API to configure optional behavior of enterprise beans:

Note:

Most of these options are provided for compatibility with other CMP implementations. Use caution when using them as they will affect application performance.
  • setDeferModificationsUntilCommit–By default TopLink defers all changes to the database until the transaction is committed. Use this method to configure TopLink to update the database after each EJB operation for the specified deferral level:

    • CMPPolicy.NONE–default behavior

    • CMPPolicy.UPDATE_MODIFICATIONS–update the database after each EJB operation for update modifications only

    • CMPPolicy.ALL_MODIFICATIONS–update the database after each EJB operation for all modifications

  • setNonDeferredCreateTime–when using nondeferred writes (see setDeferModificationsUntilCommit), use this method to configure TopLink to insert a new enterprise bean before (CMPPolicy.AFTER_EJBCREATE) or after (CMPPolicy.AFTER_EJBPOSTCREATE) the ejbPostCreate method.

  • setForceUpdate–use this method to make TopLink write all enterprise beans that have been accessed to the database regardless of whether they changed or not.

  • setUpdateAllFields–use this method to configure TopLink to force all the fields of the bean to be updated instead of only the changed fields.

  • setPessimisticLockingPolicy–use this method to configure EJB-level pessimistic locking.

119.18.2.2 Configuring BMP Information

BMP descriptors must be configured with a BMPWrapperPolicy. Neither Oracle JDeveloper nor TopLink Workbench currently support defining the BMPWrapperPolicy, so you must define this through Java code.

For more information, see Section 119.32, "Configuring Wrapper Policy".

119.19 Configuring Reading Subclasses on Queries

If you are mapping an inheritance hierarchy, by default, queries on root or branch classes return instances of the root class and their subclasses.

Alternatively, you can configure a root or branch class descriptor to do the following:

  • not include subclasses when the root or branch class is queried;

  • outer-join subclasses when the root or branch class is queried.

You can also specify a database view to optimize the reading of subclasses. The view can be used to optimize queries for root or branch classes that have subclasses spanning multiple tables. The view must apply an outer-join or union all of the subclass tables.

Do not configure this option for leaf classes.

Table 119-20 summarizes which descriptors support inherited attribute mapping configuration.

Table 119-20 Descriptor Support for Inherited Attribute Mapping Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Reading Subclasses on Queries Using TopLink Workbench
How to Configure Reading Subclasses on Queries Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported.

Unsupported Unsupported

For more information, see Section 16.2.2, "Descriptors and Inheritance".

119.19.1 How to Configure Reading Subclasses on Queries Using TopLink Workbench

To configure reading classes on subqueries, use this procedure:

  1. In the Navigator, select a root or branch descriptor.

    If the Inheritance advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Inheritance from context menu or from the Selected menu.

  2. Click the Inheritance tab.

    Figure 119-31 Inheritance Tab, Read Subclasses on Query Option

    Description of Figure 119-31 follows
    Description of "Figure 119-31 Inheritance Tab, Read Subclasses on Query Option"

Use the following information to enter data in Read Subclasses on Query and Read Subclasses View fields of the tab:

Field Description
Read Subclasses on Query Select this option to configure the root class descriptor to instantiate a subclass when the root class is queried.
Read Subclasses View Optionally select a database view to use for reading subclasses.
Outer Join All Subclasses Optionally use the outerJoinAllSubclsses option to optimize the query.

119.19.2 How to Configure Reading Subclasses on Queries Using Java

Create a descriptor amendment method (Section 119.35, "Configuring Amendment Methods") to customize the root or branch class descriptor's InheritancePolicy.

Example 119-9 shows an amendment method for the Person class. In this example, you use the InheritancePolicy method dontReadSubclassesOnQueries to configure the descriptor so that subclasses are not read on queries.

Example 119-9 Configuring Reading Subclasses on Queries

...
public static void addToPersonDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().dontReadSubclassesOnQueries();
}
...

Example 119-10 shows an amendment method for the Person class. In this example, you use the InheritancePolicy method setReadAllSubclassesViewName to optimize multiple table inheritance queries.

Example 119-10 Configuring Reading Subclasses on Queries Using a View Name

...
public static void addToPersonDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setReadAllSubclassesViewName(myView);
}
...

Example 119-11 shows an amendment method for the Person class. In this example, you use the InheritancePolicy method setShouldOuterJoinSubclasses to configure the descriptor so that subclasses are outer-joined on queries.

Example 119-11 Configuring Outer-Joining Subclasses on Queries

...
public static void addToPersonDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setShouldOuterJoinSubclasses(true);
}
...

119.20 Configuring Inheritance for a Child (Branch or Leaf) Class Descriptor

Inheritance describes how a derived (child) class inherits the characteristics of its superclass (parent). When you designate a class as a child, you must also specify the descriptor that represents the child's parent in your inheritance hierarchy.

Table 119-39 summarizes which descriptors support child inheritance configuration.

Table 119-21 Descriptor Support for Child Inheritance Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Inheritance for a Child (Branch or Leaf) Class Descriptor Using TopLink Workbench
How to Configure Inheritance for a Child (Branch or Leaf) Class Descriptor Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Supported.

Supported.

Supported.


For more information about inheritance, see Section 16.2.2, "Descriptors and Inheritance".

For more information about configuring inheritance for a parent (root) class descriptor, see Section 119.21, "Configuring Inheritance for a Parent (Root) Descriptor".

119.20.1 How to Configure Inheritance for a Child (Branch or Leaf) Class Descriptor Using TopLink Workbench

To create a child (branch or leaf class) for an inheritance, use this procedure.

  1. In the Navigator, select the descriptor you wish to specify as a child.

  2. Choose the Inheritance tab in the Property window.

    If the Inheritance tab is not visible, right-click the descriptor and choose Select Advanced Properties > Inheritance.

  3. Select the Is Child Descriptor option to specify this descriptor is a child class. The Parent Descriptor list is now enabled and the class indicator information is disabled.

    Figure 119-32 Inheritance Tab, Child Descriptor Option

    Description of Figure 119-32 follows
    Description of "Figure 119-32 Inheritance Tab, Child Descriptor Option"

Use the following information to enter data in each child descriptor field on the tab:

Field Description
Is Child Descriptor Specify that this descriptor is a child class to be used in a branch or leaf.
    Parent Descriptor Use the list to select the parent of this descriptor. See Section 16.2.2, "Descriptors and Inheritance" for more information.

119.20.2 How to Configure Inheritance for a Child (Branch or Leaf) Class Descriptor Using Java

Using Java, you can configure an inheritance child descriptor using InheritancePolicy method setParentClass, as Example 119-12 shows.

Example 119-12 Configuring an Inheritance Child Descriptor

descriptor.getInheritancePolicy().setParentClass(ChildClass.class);

119.21 Configuring Inheritance for a Parent (Root) Descriptor

Inheritance describes how a derived (child) class inherits the characteristics of its superclass (parent). When you designate a class as a parent, you can configure how TopLink handles the class's inheritance hierarchy.

Table 119-24 summarizes which descriptors support parent inheritance configuration.

Table 119-22 Descriptor Support for Parent Inheritance Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Inheritance for a Parent (Root) Descriptor Using TopLink Workbench
How to Configure Inheritance for a Parent (Root) Descriptor Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Supported.

Supported.

Supported.


For more information about configuring inheritance for a child (branch or leaf) class descriptor, see Section 119.20, "Configuring Inheritance for a Child (Branch or Leaf) Class Descriptor".

For more information, see Section 16.2.2, "Descriptors and Inheritance".

119.21.1 How to Configure Inheritance for a Parent (Root) Descriptor Using TopLink Workbench

To create a root class for an inheritance, use this procedure.

  1. In the Navigator, select the descriptor you wish to specify as the root.

  2. Choose the Inheritance tab in the Property window.

    If the Inheritance tab is not visible, right-click the descriptor and choose Select Advanced Properties > Inheritance.

  3. Select the Is Root Parent Descriptor option to specify this descriptor is a root class.

    Figure 119-33 Inheritance Tab, Configuring Inheritance for a Root Descriptor

    Description of Figure 119-33 follows
    Description of "Figure 119-33 Inheritance Tab, Configuring Inheritance for a Root Descriptor"

Use this table to complete the following root descriptor field on the Inheritance tab:

Field Description
Is Root Parent Descriptor Select this option to specify this descriptor as the root (parent) of the inheritance hierarchy.
Use Class Extraction Method Choose this option to specify a class indicator using a class extraction method, and select your static class extraction method from the list.

For more information, see Section 16.3.1.2, "Using Class Extraction Methods".

Use Class Indicator Field Choose this option to specify a class indicator using a class indicator field.

For more information, see Section 16.3.1.1, "Using Class Indicator Fields".

    Field Selection Choose the field to use as the class indicator field.
        Use XML Schema "Type" AttributeFoot 1  Select this option to use the type attribute specified in the XML schema for this descriptor's reference class.
        Specify Field For a relational descriptor, select the field of the database table associated with this descriptor (see Section 23.2, "Configuring Associated Tables").

For an EIS root descriptor (using XML records) or an XML descriptor, click Browse to select an element attribute or text node.

     Indicator Selection Choose between using a class name as the class indicator field value or specifying specific class indicator field values for each (nonabstract) child class.
        Use Class Name as Indicator Choose this option to use class names as the class indicator field value.
        Use Class Indicator Dictionary Choose this option to specify specific class indicator field values for each (nonabstract) child class.

When you choose this option, you must specify the data type of the class indicator field and the specific class indicator field values for each (nonabstract) child class.

            Indicator Type Select the data type from the list to specify the data type of the class indicator field.

To specify the specific class indicator field values for each (nonabstract) child class, click Edit and enter the appropriate value for each child class.


Footnote 1 EIS root (see Section 75.2.1.1, "EIS Root Descriptors") or XML descriptors (see Section 50.1, "XML Descriptor Concepts") only.

119.21.2 How to Configure Inheritance for a Parent (Root) Descriptor Using Java

Create a descriptor amendment method (Section 119.35, "Configuring Amendment Methods") to customize the root class descriptor's inheritance policy using InheritancePolicy methods setParentClass, setClassIndicatorFieldName, addClassIndicator, useClassNameAsIndicator and setClassExtractionMethodName, as required.

Example 119-15 shows amendment methods for the Person and Student classes where Student extends Person in a relational project. In this example, a class indicator field is used (see Section 16.3.1.1, "Using Class Indicator Fields").

Example 119-13 Configuring Inheritance for a Relational Root Class

...
public static void addToPersonDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setClassIndicatorFieldName("CLIENT_TYPE");
    descriptor.getInheritancePolicy().addClassIndicator(Student.class, indicator);
}

public static void addToStudentDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setParentClass(Person.class);
    ...
}
...

If you are using a class-extraction method (see Section 16.3.1.2, "Using Class Extraction Methods"), you may also need to use InheritancePolicy methods setOnlyInstancesExpression and setWithAllSubclassesExpression (see Section 119.22, "Configuring Inheritance Expressions for a Parent (Root) Class Descriptor").

Example 119-15 shows amendment methods for the Person and Student classes where Student extends Person in an EIS project using XML records. In this example, a class indicator field is used (see Section 16.3.1.1, "Using Class Indicator Fields").

Example 119-14 Configuring Inheritance for an EIS Root Class

...
public static void addToPersonDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setClassIndicatorField(
                                             new XMLField("@CLIENT_TYPE"));
    descriptor.getInheritancePolicy().addClassIndicator(Student.class, indicator);
}

public static void addToStudentDescriptor(Descriptor descriptor) {
    descriptor.getInheritancePolicy().setParentClass(Person.class);
    descriptor.getInheritancePolicy().setClassIndicatorField(
                                              new XMLField("@CLIENT_TYPE")
    );
}
...

119.22 Configuring Inheritance Expressions for a Parent (Root) Class Descriptor

If your class uses inheritance (see Section 16.3, "Descriptors and Inheritance") with a class extraction method (see Section 16.3.1.2, "Using Class Extraction Methods") you must provide TopLink with expressions to correctly filter sibling instances for all classes that share a common table.

Table 119-24 summarizes which descriptors support inheritance expression configuration.

Table 119-23 Descriptor Support for Inheritance Expression Configuration

Descriptor How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure Inheritance Expressions for a Parent (Root) Class Descriptor Using Java

Relational Descriptors

Unsupported Unsupported

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported Unsupported Unsupported

Figure 119-34 shows a typical inheritance hierarchy. In this example, instances of both Person and Student are stored in the same PERSON table, as Figure 119-35 shows: an instance of Person has a null value for STUDENT_NUMBER. Instances of Company are stored in a separate COMPANY table.

Figure 119-34 Example Inheritance Hierarchy

Description of Figure 119-34 follows
Description of "Figure 119-34 Example Inheritance Hierarchy"

Figure 119-35 PERSON Table

Description of Figure 119-35 follows
Description of "Figure 119-35 PERSON Table"

Queries on inheritance classes that share a common table, such as Person and Student, must filter out their sibling instances. TopLink performs this filtering using the Expression instances returned by the descriptor's InheritancePolicy methods getOnlyInstancesExpression and getWithAllSubclassesExpression.

Queries on a class that has its own table for its specific data, such as Company, and does not share this table with any sibling classes, do not require these expressions.

If you use a class indicator type field (see Section 16.3.1.1, "Using Class Indicator Fields"), TopLink automatically generates the required expressions.

If you use a class extraction method (see Section 16.3.1.2, "Using Class Extraction Methods"), you must provide TopLink with an expressions to correctly filter sibling instances for all classes that share a common table.

For concrete classes, you must define an only- instances expression.

For branch classes, you must define a with-all-subclasses expression.

When TopLink queries for a leaf class, it uses the only- instances expression to filter out any sibling classes.

When TopLink queries for a root or branch class whose subclasses do not define their own tables, it uses the with-all-subclasses expression. This is also the case when a subclass view is used (see Section 119.19, "Configuring Reading Subclasses on Queries").

When querying for a root or branch class that has subclasses that span multiple tables, a query is performed for each concrete class in the inheritance hierarchy using the only- instances expression to filter sibling classes.

When a class extraction method is used the only-instances expression is used to determine if a class is concrete. If a class does not require an only instances expression, do not enable reading subclasses on queries (see Section 119.19, "Configuring Reading Subclasses on Queries"), otherwise TopLink will assume that the class has no instances and it will skip that class on queries.

For more information about inheritance expressions, see Section 16.3.1.2.1, "Specifying Expressions for Only-Instances and With-All-Subclasses".

119.22.1 How to Configure Inheritance Expressions for a Parent (Root) Class Descriptor Using Java

Create a descriptor amendment method (Section 119.35, "Configuring Amendment Methods") to customize the root class descriptor's InheritancePolicy using InheritancePolicy methods setOnlyInstancesExpression and setWithAllSubclassesExpression, as required.

Example 119-15 shows amendment methods for the Person and Student descriptors based on the class hierarchy shown in Figure 119-34 and the database table shown in Figure 119-35.

Example 119-15 Configuring Only-Instances Expressions

...
// Only-instances expression for Person
public static void addToPersonDescriptor(Descriptor descriptor) {
    ExpressionBuilder builder = new ExpressionBuilder();
    descriptor.getInheritancePolicy().setOnlyInstancesExpression(
                              builder.getField("STUDENT_NUMBER").isNull());
}

// Only-instances expression for Student
public static void addToStudentDescriptor(Descriptor descriptor) {
    ExpressionBuilder builder = new ExpressionBuilder();
    descriptor.getInheritancePolicy().setOnlyInstancesExpression(
                              builder.getField("STUDENT_NUMBER").notNull());
}
...

Example 119-16 shows amendment methods for the Bicycle and NonFueledVehicle descriptors based on the class hierarchy shown in Figure 16-1 if the vehicle hierarchy stored all of the classes in a single vehicle table, and there was not a class indicator, but a class extraction method instead.

Example 119-16 Configuring Only-Instances and With-All-Subclasses Expressions

// Bicycle amemndment
public static void addToBicycleDescriptor(Descriptor descriptor) {
    ExpressionBuilder builder = new ExpressionBuilder();
    descriptor.getInheritancePolicy().setOnlyInstancesExpression(
                              builder.getField("BICYCLE_DESCR").notNull());
}

// NonFueldVehicle ammendment
public static void addToNonFueledVehicleDescriptor(Descriptor descriptor) {
    ExpressionBuilder builder = new ExpressionBuilder();
    descriptor.getInheritancePolicy().setWithAllSubclassesExpression(
                                    builder.getField("FUEL_TYPE").isNull());
}

119.23 Configuring Inherited Attribute Mapping in a Subclass

If you are defining the descriptor for a class that inherits attributes from another class, then you can create mappings for those attributes. If you remap an attribute that was already mapped in the superclass, then the new mapping applies to the subclass only. Any other siblings that inherit the attribute are unaffected.

If you leave inherited attributes unmapped, TopLink uses the mapping (if any) from the superclass if the superclass's descriptor has been designated as the parent descriptor.

Table 119-24 summarizes which descriptors support inherited attribute mapping configuration.

Table 119-24 Descriptor Support for Inherited Attribute Mapping Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Inherited Attribute Mapping in a Subclass Using TopLink Workbench
How to Configure Inherited Attribute Mapping in a Subclass Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Supported.

Supported.

Supported.


For more information, see Section 16.2.2, "Descriptors and Inheritance".

119.23.1 How to Configure Inherited Attribute Mapping in a Subclass Using TopLink Workbench

To map inherited attributes, use this procedure:

  1. In the Navigator, right-click a descriptor and choose Map Inherited Attributes > selected class from the context menu or choose Selected > Map Inherited Attributes from the menu.

    The mappings list now includes all the attributes from the superclass of this class.

  2. Map any desired attributes. See Chapter 120, "Creating a Mapping" for more information.

119.23.2 How to Configure Inherited Attribute Mapping in a Subclass Using Java

Using Java, attributes inherited by a subclass from a superclass will be visible and you can always create a mapping to these inherited attributes.

119.24 Configuring a Domain Object Method as an Event Handler

You can associate a domain object method with any of the descriptor events shown in Table 119-26. You can register any domain object method that complies with the following criteria:

  • Is public.

  • Returns void.

  • Takes a single parameter of type DescriptorEvent

Table 119-25 summarizes which descriptors support domain object method event handler configuration.

Table 119-25 Descriptor Support for Domain Object Method Event Handler Configuration

Descriptor How to Use Oracle JDeveloper How to Configure a Domain Object Method as an Event Handler Using TopLink Workbench
How to Configure a Domain Object Method as an Event Handler Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

For example, you can add a method handlePostDelete (that is public, returns void, and takes a single parameter of type DescriptorEvent) to your Employee object to handle PostDeleteEvent descriptor events. After you register that method with the DescriptorEventManager owned by the Employee object's descriptor as the handler for PostDeleteEvent descriptor events, whenever the Oracle TopLink runtime performs a post-delete operation on an instance of the Employee object, the runtime dispatches a PostDeleteEvent to the handlePostDelete method on the instance of the Employee object associated with that PostDeleteEvent.

The Descriptor Event ID column in Table 119-26 lists the DescriptorEventManager field name used to identify a particular event. The DescriptorEvent method getEventCode returns this value. For example:

if (descriptorEvent.getEventCode() == DescriptorEventManager.PreUpdateEvent) {
    // descriptorEvent represents a pre-update event
}

Table 119-26 Descriptor Events

Category Descriptor Event ID Description

Delete

PreDeleteEvent

Occurs before an object is deleted from the data source.

 

AboutToDeleteEvent

Occurs when an object is deleted from the data source.

 

PostDeleteEvent

Occurs after an object is deleted from the data source.

Insert

PreInsertEvent

Occurs before an object is inserted in the data source.

 

AboutToInsertEvent

Occurs when an object is inserted in the data source.

 

PostInsertEvent

Occurs after an object is inserted into the data source.

Post-X

PostBuildEvent

Occurs after an object is built from the data source.

 

PostCloneEvent

Occurs after an object has been cloned into a unit of work.

 

PostMergeEvent

Occurs after an object has been merged from a unit of work.

 

PostRefreshEvent

Occurs after an object is refreshed from the data source.

Update

PreUpdateEvent

Occurs before an object is updated in the data source. This may be called in a unit of work even if the object has no changes and does not require updating.

 

AboutToUpdateEvent

Occurs when an object is updated in the data source. This method is called only if the object has changes in the unit of work.

 

PostUpdateEvent

Occurs after an object is updated in the data source.

Write

PreWriteEvent

Occurs before an object is inserted or updated in the data source. This occurs before PreInsertEvent and PreUpdateEvent.

 

PostWriteEvent

Occurs after an object is inserted or updated in the data source. This occurs after PostInsertEvent and PostUpdateEvent.


Alternatively, you can configure a descriptor event listener as an event handler (see Section 119.25, "Configuring a Descriptor Event Listener as an Event Handler").

119.24.1 How to Configure a Domain Object Method as an Event Handler Using TopLink Workbench

To select event methods, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

    If the Events advanced property is not visible for the descriptor, then right-click the descriptor and choose Select Advanced Properties > Events from context menu or from the Selected menu.

  2. Click the Event tab in the Editor.

  3. Select the appropriate method category from the list on the left.

Use this table to enter data in the following fields to select the appropriate domain object method:

Category Option Description
Deleting Methods Pre Select the domain object method that is invoked on an instance of its reference class before the instance is deleted from the data source.
  Post Select the domain object method that is invoked on an instance of its reference class after the instance is deleted from the data source.
Inserting Methods Pre Select the domain object method that is invoked on an instance of its reference class before the instance is inserted in the data source.
  About To Select the domain object method that is invoked on an instance of its reference class when the instance is inserted in the data source.
  Post Select the domain object method that is invoked on an instance of its reference class after the instance is inserted into the data source.
Post-X Methods Build Select the domain object method that is invoked on an instance of its reference class after the instance is built from the data source.
  Clone Select the domain object method that is invoked on an instance of its reference class after the instance is cloned into a unit of work.
  Merge Select the domain object method that is invoked on an instance of its reference class after the instance is merged from a unit of work.
  Refresh Select the domain object method that is invoked on an instance of its reference class after the instance is refreshed from the data source.
Updating Methods Pre Select the domain object method that is invoked on an instance of its reference class before the instance is updated in the data source. This may be called in a unit of work even if the object has no changes and does not require updating.
  About to Select the domain object method that is invoked on an instance of its reference class when the instance is updated in the data source. This method is called only if the object has changes in the unit of work.
  Post Select the domain object method that is invoked on an instance of its reference class after the instance is updated in the data source.
Writing Methods Pre Select the domain object method that is invoked on an instance of its reference class before the instance is inserted or updated in the data source.

Note: This occurs before Pre-Insert and Pre-Update event methods are invoked.

  Post Select the domain object method that is invoked on an instance of its reference class after the instance is inserted or updated in the data source.

Note: This occurs after Post-Insert or Post-Update event methods are invoked.


119.24.2 How to Configure a Domain Object Method as an Event Handler Using Java

Example 119-17 shows a domain object class with method handlePostDelete defined to handle PostDeleteEvent descriptor events. Example 119-18 shows how to register this method as the PostDeleteEvent event handler. Whenever the TopLink runtime performs a post-delete operation on an instance of Employee, the runtime will dispatch a PostDeleteEvent to the DescriptorEventManager owned by the Employee object's descriptor. The DescriptorEventManager will then invoke the handlePostDelete method on the instance of Employee associated with that PostDeleteEvent.

Example 119-17 Domain Object Method as a Descriptor Event Handler

public class Employee {
    // domain object methods
    ...
    public void handlePostDelete(DescriptorEvent event) {
        // handler implementation
    }
}

Example 119-18 Registering a Domain Object Method as a Descriptor Event Handler

employeeDescriptor.getEventManager().setPostDeleteSelector("handlePostDelete");

119.25 Configuring a Descriptor Event Listener as an Event Handler

You can create your own DescriptorEventListner and register it with a DescriptorEventManager in a descriptor amendment method. You can also configure a DescriptorEventListner to be notified of events through the Java event model.

You can register any object that implements the DescriptorEventListener interface with the DescriptorEventManager owned by a domain object's descriptor to handle any descriptor event type (see Table 119-28). To quickly implement this interface, you can extend abstract class DescriptorEventAdapter and override only the methods for the events you are interested in.

Table 119-27 summarizes which descriptors support descriptor event listener configuration.

Table 119-27 Descriptor Support for Descriptor Event Listener Configuration

Descriptor How to Use Oracle JDeveloper How to Configure a Descriptor Event Listener as an Event Handler Using TopLink Workbench
How to Configure a Descriptor Event Listener as an Event Handler Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

For example, you create a DescriptorEventListener to handle PostBuildEvent descriptor events for Employee objects. After you register this DescriptorEventListener with the DescriptorEventManager owned by the Employee object's descriptor, whenever the TopLink runtime performs a post-build operation on an instance of Employee, the runtime dispatches a PostBuilEvent to the event listener's postBuild method.

Table 119-28 lists the DescriptorEventListener methods associated with each descriptor event. The Descriptor Event Listener Method column lists the DescriptorEventListener methods associated with each DescriptorEvent.

Table 119-28 Descriptor Events

Category Descriptor Event Listener Method Description

Delete

preDelete

Occurs before an object is deleted from the data source.

 

aboutToDelete

Occurs when an object is deleted from the data source.

 

postDelete

Occurs after an object is deleted from the data source.

Insert

preInsert

Occurs before an object is inserted in the data source.

 

aboutToInsert

Occurs when an object is inserted in the data source.

 

postInsert

Occurs after an object is inserted into the data source.

Post-X

postBuild

Occurs after an object is built from the data source.

 

postClone

Occurs after an object has been cloned into a unit of work.

 

postMerge

Occurs after an object has been merged from a unit of work.

 

postRefresh

Occurs after an object is refreshed from the data source.

Update

preUpdate

Occurs before an object is updated in the data source. This may be called in a unit of work even if the object has no changes and does not require updating.

 

aboutToUpdate

Occurs when an object is updated in the data source. This method is called only if the object has changes in the unit of work.

 

postUpdate

Occurs after an object is updated in the data source.

Write

preWrite

Occurs before an object is inserted or updated in the data source. This occurs before PreInsertEvent and PreUpdateEvent.

 

postWrite

Occurs after an object is inserted or updated in the data source. This occurs after PostInsertEvent and PostUpdateEvent.


Alternatively, you can configure a domain object method as an event handler (see Section 119.24, "Configuring a Domain Object Method as an Event Handler").

119.25.1 How to Configure a Descriptor Event Listener as an Event Handler Using TopLink Workbench

For more information, see Section 119.24.1, "How to Configure a Domain Object Method as an Event Handler Using TopLink Workbench".

119.25.2 How to Configure a Descriptor Event Listener as an Event Handler Using Java

Example 119-19 shows a DescriptorEventListener that handles PostBuildEvent descriptor events. Example 119-20 shows how to register this DescriptorEventListener with the Employee object's descriptor. Whenever the TopLink runtime performs a post-build operation on an instance of Employee, the runtime will dispatch a post build event to the corresponding DescriptorEventListener method on each registered event listener (in this case, it calls the postBuild method).

Example 119-19 DescriptorEventListener

public class MyDescriptorEventListener extends DescriptorEventAdapter {

    public void postBuild(DescriptorEvent event) {
        // handler implementation
    }
}

Example 119-20 Registering a DescriptorEventListener with the DescriptorEventManager

descriptor.getEventManager().addListener(new MyDescriptorEventListener());

119.26 Configuring Locking Policy

You can configure a descriptor with a locking policy that prevents one user writing over another user's work.

Table 119-29 summarizes which descriptors support locking policies.

Table 119-29 Descriptor Support for Locking Policy

Descriptor Optimistic Version Locking Policies
Optimistic Field Locking Policies
Pessimistic Locking Policy
How to Use Oracle JDeveloper How to Configure Locking Policy UsingTopLink Workbench
How to Configure Locking Policy Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Supported.

Supported.

Supported.

Unsupported.

Unsupported.

Supported.

EIS DescriptorsFoot 2 

Supported.

Unsupported.

Supported.

Supported.

Supported.

Supported.

XML Descriptors

Unsupported.

Unsupported.

Unsupported.

Unsupported.

Unsupported.

Unsupported.


Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

Oracle recommends that you use a locking policy. You should use a locking policy in any multiuser environment to prevent one user writing over another user's changes. Although locking can be particularly important if multiple servers or multiple applications access the same data, even in a single server application, the same locking issue still exists. In a multiple-server environment, locking is still relevant even if your application uses cache refreshing or cache coordination.

If you are building a three-tier application, in order to correctly lock an object, you must obtain the lock before the object is sent to client to be edited. The type of locking you choose has an influence on how you can achieve this (see Section 16.4.6, "Locking in a Three-Tier Application").

119.26.1 How to Configure Locking Policy UsingTopLink Workbench

To specify a descriptor's locking policy, use this procedure:

  1. In the Navigator, select a relational or EIS root descriptor.

    If the Locking advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Locking from the context menu or from the Selected menu.

  2. Click the Locking tab.

    Figure 119-37 Locking Tab for a Descriptor

    Description of Figure 119-37 follows
    Description of "Figure 119-37 Locking Tab for a Descriptor"

    Figure 119-38 Locking Tab for an EIS Root Descriptor

    Description of Figure 119-38 follows
    Description of "Figure 119-38 Locking Tab for an EIS Root Descriptor"

Use this table to enter data in the following fields on the tab of the appropriate type:

Field Description
Optimistic Locking Specify that the descriptor uses optimistic locking.
    By Version Specify to use optimistic locking, based on versioning.
        Database Field Select the database field that contains the version value used for optimistic locking.

This field appears for relational descriptors only.

        XPath Click Browse to define the path to the element or attribute that stores the version value.

This field appears for EIS root descriptors only.

Ensure that the attribute's type corresponds to the type of locking policy you choose (numeric for Version Locking and timestamp for Timestamp Locking).

        Version Locking Specify that the descriptor uses numeric version locking. The version field (defined by the Database Field, for relational descriptors, or the XPath, for EIS root descriptors) must be a numeric type
        Timestamp Locking Specify that the descriptor uses time stamp version locking, based on time stamp. The version field (defined by the Database Field, for relational descriptors, or the XPath, for EIS root descriptors) must be a timestamp type.
        Store Version in Cache Specify whether or not you want to store the version information in the cache.

If you choose not to define a mapping for the version field, then you must enable this option to configure the descriptor to store the version value in the Oracle TopLink cache.

If you choose to define a mapping for the version field, then you must disable this option in order to store the version value in the object.

For more information, see Section 16.4.6.1, "Optimistic Locking in a Three-Tier Application".

    By FieldsFoot 1  Specify to use optimistic locking, based on database fields.

These fields appear for relational descriptors only.

        All Fields Select all fields for optimistic locking.
        Changed Fields Select only the changed fields for optimistic locking.
        Selected Fields Click Add to select specific database fields for optimistic locking.
Pessimistic Locking Specify to use pessimistic locking for this descriptor.

This applies only to descriptors that have had EJB CMP information configured for them (see Section 119.18, "Configuring a Descriptor with EJB CMP and BMP Information").

     Wait for Lock Specify whether or not TopLink should wait for a data source lock. When not selected, the thread of execution will immediately throw a DatabaseException if it cannot acquire a read lock on the object.

When selected, the thread of execution will wait indefinitely until the read lock is released, at which time, it will attempt to acquire it. Use this option with care as it can lead to application deadlocks.


Footnote 1  You cannot use field locking with the AttributeChangeTrackingPolicy (see Section 113.2.3.3, "Attribute Change Tracking Policy").

119.26.2 How to Configure Locking Policy Using Java

This section describes the following:

119.26.2.1 Configuring an Optimistic Locking Policy

Use the ClassDescriptor method setOptimisticLockingPolicy to set an instance of the appropriate optimistic field locking policy:

  • AllFieldsLockingPolicy

  • ChangedFieldsLockingPolicy

  • SelectedFieldsLockingPolicy

  • VersionLockingPolicy

  • TimestampLockingPolicy

Use the ClassDescriptor method getOptimisticLockingPolicy to get the selected locking policy type and configure it.

119.26.2.2 Configuring Optimistic Locking Policy Cascading

If you are using a VersionLockingPolicy, you can enable cascading to configure TopLink to automatically force a version field update on a parent object when its privately owned child object's version field changes. Use VersionLockingPolicy method setIsCascaded passing in a boolean of true to enable cascading, or false to disable cascading.

For more information, see Section 16.4.2, "Optimistic Version Locking Policies and Cascading".

119.26.2.3 Configuring a Pessimistic Locking Policy

You can configure a descriptor with a PessimisticLockingPolicy only when using a CMPPolicy. That is, you only can configure a PessimisticLockingPolicy for descriptors that support EJB CMP information (see Section 119.18, "Configuring a Descriptor with EJB CMP and BMP Information") in a CMP project.

Instantiate a CMPPolicy and use CMPPolicy method setPessimisticLockingPolicy to set an instance of PessimisticLockingPolicy. Then use the ClassDescriptor method setCMPPolicy to set the CMPPolicy.

119.27 Configuring Returning Policy

Using a ReturningPolicy, you can obtain field values from the data source when inserting or updating an object. TopLink uses the values that the data source returns to update the object attributes that map to these fields. You can specify which fields to return for inserts and updates. For insert fields, you can also specify whether or not to include the field value in the insert operation.

A ReturningPolicy is useful when the data source provides default or initial field values through defaults, triggers, or stored procedures. You can also use a ReturningPolicy to allow the data source to assign a sequence or primary key value.

Any object attribute that you do not configure in a descriptor's ReturningPolicy receives the default behavior: in the context of a unit of work, if the attribute has changed, its value is written to the database. If the SQL statement invokes a trigger or stored procedure that modifies the database field, the database generated value is not reflected by the object.

Use caution when deciding on whether or not to use a ReturningPolicy, as doing so may effect insert or update performance and is not compatible with batch writing (see Section 12.11.3, "How to Use Batch Writing for Optimization").

By default, you can use a ReturningPolicy with Oracle Database, in which case, TopLink uses the Oracle RETURNING clause (see Section 119.27.1, "How to Configure Returning Policy Using TopLink Workbench").

You can use a ReturningPolicy with a non-Oracle database if you configure your descriptor's insert or update query to use a stored procedure that returns the desired returned values as output parameters (see Section 119.27.2, "How to Configure Returning Policy Using Java").

Table 119-39 summarizes which descriptors support returning policy configuration.

Table 119-30 Descriptor Support for Fetch Group Configuration

Descriptor How to Use Oracle JDeveloper How to Configure Returning Policy Using TopLink Workbench
How to Configure Returning Policy Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 1 

Supported.

Supported.

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Footnote 1 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

119.27.1 How to Configure Returning Policy Using TopLink Workbench

To specify the return policy for a descriptor, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

    If the Returning advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Returning from the context menu or from the Selected menu.

  2. Click the Returning tab in the Editor.

    Figure 119-39 Returning Tab

    Description of Figure 119-39 follows
    Description of "Figure 119-39 Returning Tab"

Use the following information to enter data in each field on the tab:

Field Description
Insert These options apply to insert operations:
    Name Click Add to add a database field to this ReturningPolicy for insert operations.
    ReturnEonly When selected, TopLink only returns a value for this field; it will not include the field in the insert.

When not selected, TopLink returns a value for this field and includes the value in the insert.

Update These options apply to update operations:
    Name Click Add to add a database field to this ReturningPolicy for update operations

To remove a database field from the descriptor's ReturningPolicy, select the field in the Insert or Update window and click Remove.

Note:

If you are using TopLink Workbench, you cannot configure a returning policy for an attribute mapped with a transformation mapping (see Section 27.13, "Transformation Mapping").

119.27.2 How to Configure Returning Policy Using Java

You use a ReturningPolicy to configure how TopLink handles returning with the attributes of an object on a field-by-field basis. Table 119-31 describes the ReturnPolicy methods you use to tell TopLink how to handle a particular database field. Each method takes a String or a DatabaseField type parameter as field name.

Table 119-31 Return Policy Methods

Method Applies to SQL Statements of Type... Writes Current Value of Field to Database? Returns Database- Generated Result?

addFieldForInsert

INSERT

Yes

Yes

addFieldForInsertReturnOnly

INSERT

No

Yes

addFieldForUpdate

UPDATE

Yes

Yes


You configure a descriptor with a ReturningPolicy using ClassDescriptor method setReturningPolicy.

119.28 Configuring Instantiation Policy

The TopLink runtime instantiates new instances of a class according to the instantiation policy you configure on the class's descriptor.

Table 119-32 summarizes which descriptors support an instantiation policy.

Table 119-32 Descriptor Support for Instantiation Policy

Descriptor How to Use Oracle JDeveloper How to Configure Instantiation Policy Using TopLink Workbench
How to Configure Instantiation Policy Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Supported.

Supported.

Supported.


You can specify one of the following types of instantiation policy:

  • Default: TopLink creates a new instance of a class by calling the class's default constructor.

  • Method: TopLink creates a new instance of a class by calling a public static method that you define on the class descriptor.

  • Factory: TopLink creates a new instance of a class by calling the appropriate methods on a separate class that you implement according to the Factory design pattern.

119.28.1 How to Configure Instantiation Policy Using TopLink Workbench

To set the instantiation policy for a descriptor, use this procedure:

  1. In the Navigator, select a descriptor.

    If the Instantiation advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Instantiation from the context menu or from the Selected menu.

  2. Click the Instantiation tab.

    Figure 119-40 Instantiation Tab

    Description of Figure 119-40 follows
    Description of "Figure 119-40 Instantiation Tab"

Use the following information to enter data in each field on the tab:

Field Description
Use Default Constructor Specify if the default constructor of the class instantiates a new instance.
Use Method Specify a method to execute to create objects from the database.
    Method
Select the name of a method to be executed to create objects from the database. The method must be a public, static method on the descriptor's class and must return a new instance of the object.
Use Factory Specify an object factory method.
    Factory Class Select the class of the factory object that creates the new instances.
    Factory Method Select the method to be used to obtain a factory object. Choose <nothing> to use the default constructor.
    Instantiation Method Select the method to be called on the factory object to obtain a new instance that will be populated with data from the data source.

119.28.2 How to Configure Instantiation Policy Using Java

Use one of the following ClassDescriptor methods to set the appropriate type of instantiation policy:

  • useDefaultConstructorInstantiationPolicy

  • useMethodInstantiationPolicy

  • useFactoryInstantiationPolicy

119.29 Configuring Copy Policy

The TopLink unit of work feature must be able to produce an exact copy (clone) persistent objects. Table 119-33 summarizes which descriptors support a copy policy.

Table 119-33 Configuring Descriptors with a Copy Policy

Descriptor How to Use Oracle JDeveloper How to Configure Copy Policy Using TopLink Workbench
How to Configure Copy Policy Using Java

Relational Descriptors

Supported.

Supported.

Supported.

Object-Relational Data Type Descriptors

Unsupported.

Unsupported.

Supported.

EIS Descriptors

Supported.

Supported.

Supported.

XML Descriptors

Supported.

Supported.

Supported.


TopLink supports the following two ways of copying objects:

  • Instantiation policy: By default, TopLink creates a new copy of an object by using the currently configured instantiation policy (see Section 119.28, "Configuring Instantiation Policy").

  • Method: TopLink creates a new copy of an object by calling a method on the object that you specify. For example, you can specify the object's clone method (or any other appropriate method on the object). Note that the clone method should return a shallow clone of the object.

119.29.1 How to Configure Copy Policy Using TopLink Workbench

To specify the copy policy for a descriptor, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

    If the Copying advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Copying from the context menu or from the Selected menu.

  2. Click the Copying tab in the Editor.

    Figure 119-41 Copying Tab

    Description of Figure 119-41 follows
    Description of "Figure 119-41 Copying Tab"

Use the following information to enter data in each field on the tab:

Field Description
Use Instantiation Policy Creates a new instance of the object using the descriptor's instantiation policy (see Section 119.28, "Configuring Instantiation Policy").
Use Clone Method Specifies whether or not to call the clone method of the object. Select a method from the list.

119.29.2 How to Configure Copy Policy Using Java

Use one of the following ClassDescriptor methods to set the appropriate type of copy policy:

  • useCloneCopyPolicy(): the object must provide a clone method

  • useCloneCopyPolicy(java.lang.String cloneMethodName)

  • useInstantiationCopyPolicy()

119.30 Configuring Change Policy

Use a change policy to specify how TopLink should track changes made to objects after you register them with a unit of work. Table 119-34 summarizes which descriptors support a change policy.

Table 119-34 Descriptor Support for Change Policy

Descriptor Deferred Change Detection Policy
Object-Level Change Tracking Policy
Attribute Change Tracking Policy
How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure Change Policy Using Java

Relational DescriptorsFoot 1 

Supported.

Supported.

Supported.

Unsupported Unsupported

Supported.

Object-Relational Data Type Descriptors

Supported.

Supported.

Supported.

Unsupported Unsupported

Supported.

EIS DescriptorsFoot 2 

Supported.

Supported.

Supported.

Unsupported Unsupported

Supported.

XML Descriptors

Unsupported Unsupported Unsupported Unsupported Unsupported Unsupported

Footnote 1 Relational class descriptors only (see Section 22.2.1.1, "Creating Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see Section 75.2.1.1, "EIS Root Descriptors").

By default, TopLink uses the deferred change detection policy.

For JPA entities or POJO classes that you configure for weaving, TopLink weaves value holder indirection for one-to-one mappings. If you want TopLink to weave change tracking and your application includes collection mappings (one-to-many or many-to-many), then you must configure all collection mappings to use transparent indirect container indirection only (you may not configure your collection mappings to use eager loading nor value holder indirection).

Mutable basic mappings affect the overhead of change tracking. TopLink can only weave an attribute change tracking policy for immutable mappings.

TopLink logs a warning message at the CONFIG log level if you try to weave a descriptor that does not support change policy.

TopLink supports alternative change policies (policies other than DeferredChangeDetectionPolicy) for attributes that use a subset of the mappings that TopLink supports.

For CMP and JPA applications deployed to OC4J TopLink automatically uses the attribute change tracking policy.

For more information, see the following:

119.30.1 How to Configure Change Policy Using Java

This section describes how to configure a descriptor with a change policy using Java, and how to implement persistent classes for those change policies that are intrusive. It includes information on configuring the following:

119.30.1.1 Configuring Deferred Change Detection Policy

The DeferredChangeDetectionPolicy provides good unit of work commit performance for a wide range of object change characteristics. It is the default change policy. For more information, see Section 113.2.3.1, "Deferred Change Detection Policy").

Because it is the default, you do not need to explicitly configure this policy.

To configure TopLink to use a DeferredChangeDetectionPolicy, create a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") that sets the change policy, as Example 119-21 illustrates.

119.30.1.2 Configuring Object Change Tracking Policy

The ObjectChangeTrackingPolicy provides improved unit of work commit performance for objects with few attributes, or with many attributes and many changed attributes. For more information, see Section 113.2.3.2, "Object-Level Change Tracking Policy").

For CMP and JPA applications deployed to an application server, for which TopLink provides CMP integration (see Section 8.1, "Introduction to the Application Server Support"), when you configure an entity bean's descriptor with an ObjectLevelChangeTrackingPolicy, TopLink automatically generates code of a concrete subclass to implement the TopLink ChangeTracker interface at deploy time. Configuring an ObjectLevelChangeTrackingPolicy prevents TopLink from automatically applying an AttributeChangeTrackingPolicy (see Section 119.30.1.3, "Configuring Attribute Change Tracking Policy").

To configure TopLink to use an ObjectChangeTrackingPolicy, use this procedure:

  1. Create a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") that sets the change policy, as Example 119-21 illustrates.

    Example 119-21 Setting the ObjectChangeTrackingPolicy

    descriptor.setObjectChangePolicy(new ObjectChangeTrackingPolicy());
    
  2. For plain Java objects, code each of your persistent classes to implement the ChangeTracker interface, as Example 119-22 illustrates.

    Example 119-22 Implementing the ChangeTracker Interface for the ObjectChangeTrackingPolicy

    public class Employee implements ChangeTracker {
    
        PropertyChangeListener listener;
        String firstName;
    
        public PropertyChangeListener getTopLinkPropertyChangeListener() {
          return this.listener;
        }
    
        public void setTopLinkPropertyChangeListener(PropertyChangeListener listener) {
          this.listener = listener;
        }
    ...
        public void setFirstName(String firstName) {
          propertyChange("firstName", getFirstName(), firstName);
          this.firstName = firstName;
        }
    ...
        public void propertyChange(String propertyName, Object oldValue, Object newValue) {
            if (listener != null) {
                if (oldValue != newValue) {
                    listener.propertyChange(
                        new PropertyChangeEvent(this, propertyName, oldValue, newValue));
                }
            }
        }
    }
    

119.30.1.3 Configuring Attribute Change Tracking Policy

The AttributeChangeTrackingPolicy provides improved unit of work commit performance for objects with many attributes and few changed attributes. In general, this is the most efficient change policy. It is the default change policy for JPA and EJB 2.n CMP applications deployed to OC4J. For more information, see Section 113.2.3.3, "Attribute Change Tracking Policy").

Note:

You cannot use the AttributeChangeTrackingPolicy if you are using any instance of FieldsLockingPolicy (see Section 16.4.4, "Optimistic Field Locking Policies").

When you deploy a TopLink-enabled EJB 3.0 persistent application or EJB 2.n CMP application to OC4J, TopLink automatically configures your persistent classes to use the AttributeChangeTrackingPolicy and, using bytecode weaving (EJB 3.0) or code generation (EJB 2.n), configures your persistence classes to implement the TopLink ChangeTracker interface. In this case, you do not need to explicitly configure this change policy.

To configure TopLink to use an AttributeChangeTrackingPolicy for plain Java objects or other application servers, use this procedure:

  1. Create a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") that sets the change policy as Example 119-23 illustrates.

    Example 119-23 Setting the DeferredChangeDetectionPolicy

    descriptor.setObjectChangePolicy(new AttributeChangeTrackingPolicy());
    
  2. Code each of your persistent classes to implement the ChangeTracker interface, as Example 119-24 illustrates.

    Example 119-24 Implementing the ChangeTracker Interface for the AttributeChangeTrackingPolicy

    public class Employee implements ChangeTracker {
    
        PropertyChangeListener listener;
        String firstName;
    
        public PropertyChangeListener getTopLinkPropertyChangeListener() {
          return this.listener;
        }
    
        public void setTopLinkPropertyChangeListener(PropertyChangeListener listener) {
          this.listener = listener;
        }
    ...
        public void setFirstName(String firstName) {
          propertyChange("firstName", getFirstName(), firstName);
          this.firstName = firstName;
        }
    ...
        public void propertyChange(String propertyName, Object oldValue, Object newValue) {
            if (listener != null) {
                if (oldValue != newValue) {
                    listener.propertyChange(
                        new PropertyChangeEvent(this, propertyName, oldValue, newValue));
                }
            }
        }
    }
    

119.31 Configuring a History Policy

If you want to use historical sessions (see Section 87.6, "Historical Sessions") to execute historical queries (see Section 108.11, "Historical Queries") against a historical schema of your own design, configure your descriptors with a TopLink HistoryPolicy that describes your historical schema.

If you are using Oracle Database platform for Oracle9i Database (or later), you can query the historical versions of objects automatically maintained by Oracle Database without the need for a history policy. For more information, see Section 93.1.1, "How to Configure Historical Sessions Using an Oracle Platform".

Table 119-35 summarizes which descriptors support history policy configuration.

Table 119-35 Descriptor Support for History Policy Configuration

Descriptor How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure a History Policy Using Java

Relational Descriptors

Unsupported Unsupported

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported Unsupported Unsupported

There are many ways to configure a historical database schema. TopLink supports several historical schema configurations that you can describe with a HistoryPolicy (see Section 87.6.1, "Historical Session Limitations").

Example Historical Schema

As shown in Table 119-36 and Table 119-37, a common approach is to define a special history table to store past versions of an object: one history table for each regular table that requires historical persistence. The history table typically has the same fields as the corresponding regular table plus fields (such as row start and end) used to define an interval that represents the life time of a particular version.

Note:

TopLink assumes that the current version of an object corresponds to the historical table row whose row end field is NULL.

TopLink will include the history tables described by a HistoryPolicy when you execute a historical query.

Table 119-36 shows the schema for an EMPLOYEE table. The table currently contains one EMPLOYEE instance.

Table 119-36 Example Table for EMPLOYEE

EMP_ID F_NAME L_NAME SALARY

1

Jane

Doe

55000


Table 119-37 shows one possible history table EMPLOYEE_HIST that stores historical versions of employees. The table contains the current EMPLOYEE (the version with a ROW_END value of NULL) and one historical version.

Table 119-37 Example History Table EMPLOYEE_HIST

EMP_ID F_NAME L_NAME SALARY ROW_START ROW_END

1

Jane

Doe

50000

29/08/2004

31/08/2004

1

Jane

Doe

55000

31/08/2004

NULL


Because every record has a start and end interval, the history table can store multiple versions of the same object (with the same primary key). The unique identifier of a particular version is given by the existing primary key, plus the value of the start field. For example, in Table 119-37, the unique identifier of the current version is given by (EMP_ID, START) = (1, 31/08/2004).

119.31.1 How to Configure a History Policy Using Java

Example 119-25 shows how to describe the schema shown in Table 119-36 and Table 119-37 using the TopLink HistoryPolicy:

Example 119-25 HistoryPolicy for One Table

HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("ROW_START");
policy.addEndFieldName("ROW_END");
policy.addHistoryTableName("EMPLOYEE", "EMPLOYEE_HIST");
// Assuming database triggers or stored procedures update history tables
policy.setShouldHandleWrites(false);

employeeDescriptor.setHistoryPolicy(policy);

You can specify more than one table with a HistoryPolicy as shown in Example 119-26. In this example, all history tables have a start field named ROW_START but the EMPLOYEE_HIST and SALARY_HIST tables have different end fields. To avoid ambiguity, the end field names are prefixed with their respective history table names.

Example 119-26 HistoryPolicy for Multiple Tables

HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("ROW_START");
policy.addEndFieldName("EMPLOYEE_HIST.ROW_END");
policy.addEndFieldName("SALARY_HIST.VALID_UNTIL");
policy.addHistoryTableName("EMPLOYEE", "EMPLOYEE_HIST");
policy.addHistoryTableName("SALARY", "SALARY_HIST");
// Assuming database triggers or stored procedures update history tables
policy.setShouldHandleWrites(false);

employeeDescriptor.setHistoryPolicy(policy);

119.31.1.1 Configuring Write Responsibility

Use HistoryPolicy method setShouldHandleWrites to specify whether or not TopLink is responsible for writing data to history tables. By default, setShouldHandleWrites is set to true.

Either the database or TopLink can be responsible for writing data to the history tables.

You can configure the database to write data to history tables by way of triggers or stored procedures that customize create, insert, and delete operations to modify both the regular table and the history table appropriately.

119.32 Configuring Wrapper Policy

TopLink lets you use wrappers (or proxies) in cases where the persistent class is not the same class that is to be presented to users.

For example, in the EJB specification prior to 3.0, the entity bean class (the class that implements javax.ejb.EntityBean) is persistent, but is hidden from users who interact with a class that implements javax.ejb.EJBObject (local or remote interface class). In this example, the EJBObject acts as a proxy (or wrapper) for the EntityBean.

In cases where such a wrapper is used, TopLink continues to make the class specified in the descriptor persistent, but returns the appropriate instance of the wrapper whenever a persistent object is requested.

Table 119-38 summarizes which descriptors support a wrapper policy.

Table 119-38 Descriptor Support for Wrapper Policy

Descriptor How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure Wrapper Policy Using Java

Relational Descriptors

Unsupported Unsupported

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported

Supported.

XML Descriptors

Unsupported Unsupported Unsupported

Use a wrapper policy to tell TopLink how to create wrappers for a particular persistent class, and how to obtain the underlying persistent object from a given wrapper instance.

If you specify a wrapper policy, TopLink uses the policy to wrap and unwrap persistent objects as required:

  • Wrapper policies implement the interface oracle.toplink.descriptors.WrapperPolicy.

  • A wrapper policy is specified by setting the wrapper policy for the TopLink descriptor.

  • By default, no wrapper policy is used (the wrapper policy for a descriptor is null by default).

Note:

Wrapper policies are advanced TopLink options. Using a wrapper policy may not be compatible with some TopLink Workbench features.

For CMP descriptors, the EJB wrapper policy is automatically configured during deployment, so does not need to be set in the descriptor (see Section 119.18, "Configuring a Descriptor with EJB CMP and BMP Information").

For BMP descriptors, you must set a BMPWrapperPolicy on the descriptor. The BMPWrapperPolicy includes the bean's information including the bean-name, primary-key-class, home-interface, and remote-interface.

Wrapper policies cannot be set using Oracle JDeveloper or TopLink Workbench and can be set only using Java code (see Section 119.32.1, "How to Configure Wrapper Policy Using Java").

119.32.1 How to Configure Wrapper Policy Using Java

Use the ClassDescriptor method setWrapperPolicy to set the appropriate instance of WrapperPolicy.

Example 119-27 shows how to amend a BMP descriptor with the required BMP information.

Example 119-27 Configuring a BMP Wrapper Policy

public static void addToDescriptor(ClassDescriptor descriptor) {
    BMPWrapperPolicy policy = new BMPWrapperPolicy(
                                           "employee",
                                           EmployeeHome.class,
                                           EmployeePK.class,
                                           Employee.class,
                                           new Hashtable());
    descriptor.setWrapperPolicy(policy);

119.33 Configuring Fetch Groups

By default, when you execute an object-level read query for a particular object class, TopLink returns all the persistent attributes mapped in the object's descriptor. With this single query, all the object's persistent attributes are defined, and calling their get methods returns the value directly from the object.

When you are interested in only some of the attributes of an object, it may be more efficient to return only a subset of the object's attributes using a fetch group.

Using a fetch group, you can define a subset of an object's attributes and associate the fetch group with either a ReadObjectQuery or ReadAllQuery query. When you execute the query, TopLink retrieves only the attributes in the fetch group. TopLink automatically executes a query to fetch all the attributes excluded from this subset when and if you call a get method on any one of the excluded attributes.

You can define more than one fetch group for a class. You can optionally designate at most one such fetch group as the default fetch group. If you execute either a ReadObjectQuery or ReadAllQuery query without specifying a fetch group, TopLink will use the default fetch group, unless you configure the query otherwise (see Section 111.3.1, "How to Configure Default Fetch Group Behavior").

You can use fetch groups in CMP or JPA projects for EJB objects, as well as for POJO classes.

Before using fetch groups, Oracle recommends that you perform a careful analysis of system use. In many cases, the extra queries required to load attributes not in the fetch group could well offset the gain from the partial attribute loading. For more information about optimizing read performance, see Section 12.12.9, "Read Optimization Examples".

Table 119-39 summarizes which descriptors support fetch group configuration.

Table 119-39 Descriptor Support for Fetch Group Configuration

Descriptor How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure Fetch Groups Using Java

Relational Descriptors

Unsupported Unsupported

Supported.

Object-Relational Data Type Descriptors

Unsupported Unsupported

Supported.

EIS Descriptors

Unsupported Unsupported Unsupported

XML Descriptors

Unsupported Unsupported Unsupported

For JPA entities or POJO classes that you configure for weaving, TopLink uses fetch groups to improve performance.

This section describes how to create a fetch group, store it in a descriptor, and optionally designate a fetch group as the default fetch group for its descriptor reference class.

For more information, see the following:

119.33.1 How to Configure Fetch Groups Using Java

To configure a fetch group, use a descriptor amendment method (see Section 119.35, "Configuring Amendment Methods") as Example 119-28 shows.

Example 119-28 Configuring a Fetch Group

//Create a FetchGroupManager for the descriptor
descriptor.setFetchGroupManager(new FetchGroupManager());
// Create a FetchGroup
FetchGroup group = new FetchGroup("nameOnly");
// Add attributes to FetchGroup. Alternatively, use
// FetchGroup method addAttributes, passing in a Set of String attribute names
group.addAttribute("firstName");
group.addAttribute("lastName");
// Add the FetchGroup to the FetchGroupManager
descriptor.getFetchGroupManager().addFetchGroup(group);
//Set the default fetch group
descriptor.getFetchGroupManager().setDefaultFetchGroup(group);

Each instance of FetchGroup that you store in a descriptor must be configured with a fetch group name that is unique for that descriptor (that is, each descriptor owns a set of named fetch groups).

When configuring fetch groups, note that the primary key fields and other required fields (such as inheritance type and optimistic lock version) are always included in all fetch groups.Fetch groups can include direct and relationship attributes. Including a relationship attribute in a fetch group does not cause the relationship to be joined or instantiated: joining and indirection are set independently of fetch groups.

After you add a fetch group to a descriptor, you can configure a ReadObjectQuery or ReadAllQuery query with this fetch group by name (nameOnly) or rely on TopLink to use this fetch group by default. For more information, see Section 111.3, "Using Queries with Fetch Groups".

119.34 Configuring a Descriptor Customizer Class

A descriptor customizer class is a Java class that implements the oracle.toplink.tools.sessionconfiguration.DescriptorCustomizer interface and provides a default (zero-argument) constructor. You can use a descriptor customizer to customize a descriptor at run time on a loaded session before login occurs, similar to how you can use an amendment method (see Section 119.35, "Configuring Amendment Methods").

Table 119-40 summarizes which sessions support customizer class configuration.

Table 119-40 Descriptor Support for Customizer Class Configuration

Descriptor How to Use Oracle JDeveloper How to Use TopLink Workbench How to Configure Customizer Class Using Java

Relational Descriptors

Supported.

Unsupported

Supported.

Object-Relational Data Type Descriptors

Supported.

Unsupported

Supported.

EIS Descriptors

Supported.

Unsupported

Supported.

XML Descriptors

Supported.

Unsupported

Supported.


For more information, see Section 16.2.6, "Descriptor Customization".

119.34.1 How to Configure Customizer Class Using Java

When using Java, create a customize class that implements the oracle.toplink.tools.sessionconfiguration.DescriptorCustomizer interface. Example 119-29 illustrates the creation of a descriptor customizer.

Example 119-29 Creating a SessionCustomizer Class

import oracle.toplink.tools.sessionconfiguration.DescriptorCustomizer;
import oracle.toplink.descriptors.ClassDescriptor;

public class EmployeeDescriptorCustomizer implements DescriptorCustomizer {

    public void customize(ClassDescriptor descriptor) {
        descriptor.setReadOnly();
    }
}

119.35 Configuring Amendment Methods

Some TopLink descriptor features cannot be configured from Oracle JDeveloper or TopLink Workbench. To use these features, you must write a Java method to amend the descriptor after it is loaded as part of the project. This method must have the following characteristics:

  • Be public static.

  • Take a single parameter of type oracle.toplink.descriptors.ClassDescriptor.

In the implementation of this method, you can configure advanced features of the descriptor using any of the public descriptor and mapping API.

Table 119-41 summarizes which descriptors support amendment methods.

Table 119-41 Descriptor Support for Amendment Methods

Descriptor How to Use Oracle JDeveloper How to Configure Amendment Methods Using TopLink Workbench
How to Use Java

Relational Descriptors

Supported.

Supported.

Unsupported

Object-Relational Data Type Descriptors

Unsupported Unsupported Unsupported

EIS Descriptors

Supported.

Supported.

Unsupported

XML Descriptors

Supported.

Supported.

Unsupported

This section describes how to associate an amendment method with a descriptor.

For more information about how to implement an amendment method, see Section 16.2.7, "Amendment and After-Load Methods".

Alternatively, you can use a descriptor customizer class (see Section 119.34, "Configuring a Descriptor Customizer Class"

To customize a session, use a session customizer class (see Section 89.8, "Configuring a Session Customizer Class").

119.35.1 How to Configure Amendment Methods Using TopLink Workbench

To use an amendment method with a descriptor (after it is loaded as part of the project) use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

    If the After load advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > After Load from context menu or from the Selected menu.

  2. Click the After Load tab in the Editor.

    Figure 119-42 After Load Tab

    Description of Figure 119-42 follows
    Description of "Figure 119-42 After Load Tab"

Field Description
Class Click Browse and choose the class of the method to execute.
Static Method Use the Static Method list to choose the static method to execute at run time, after loading the descriptor. The method must be public static and take a single attribute of type oracle.toplink.descriptors.ClassDescriptor.