Specifying Direct Access and Method Access

By default, TopLink uses direct access to access public attributes. Alternatively, you can use accessor methods to access object attributes when writing the attributes of the object to the database or reading the attributes of the object from the database. This is known as method access.

The attribute's visibility (public, protected, private, or package visibility) and the supported version of JDK may restrict the type of access that you can use.

Starting with JDK 1.2, the Java Core Reflection API provides a means to suppress default Java language access control checks when using reflection. TopLink uses reflection to access the application's persistent objects. This means that if you are using a VM that supports the API, then TopLink can access an attribute directly, regardless of its declared visibility.


Note: To use private variable access with JDK 1.2, you must enable the security setting. Consult the JDK documentation for more information.

Oracle recommends using direct access whenever possible to improve performance and avoid executing any application-specific behavior while building objects.

Setting the Access Type

Use the General tab of the specific mapping (see Figure 5-2) to set the access type as direct or method-based.

To change the default access type used by all new mappings, use the Defaults tab on the TopLink Mapping editor. See "Specifying Default Properties" for more information.


Note: If you change the access default, existing mappings retain their current access settings, but new mappings will be created with the new default.

Related Topics

About TopLink Descriptors

About TopLink Mapping Types
Working with Common Mapping Properties
Specifying Read Only Settings
Defaulting Null Values
Maintaining Bidirectional Relationships
Specifying Field Names and Multiple Tables
Specifying Collection Properties
Specifying Mapping Information in ejb-jar.xml File
Working with Descriptors

 

Copyright © 1997, 2004, Oracle. All rights reserved.