Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@VirtualAccessMethods

Use @VirtualAccessMethods to specify that a specific class contains virtual methods.


Annotation Elements

Table 2-79 describes this annotation's elements.

Table 2-79 @VirtualAccessMethods Annotation Elements

Annotation Element Description Default

get

(Optional) Name of the getter method to use for the virtual property This method must take a single java.lang.String parameter and return a java.lang.Object.

If get is specified, you must also specify set.

get

set

(Optional) Name of the setter method to use for the virtual property This method must take a java.lang.String parameter and a java.lang.Object parameter.

If set is specified, you must also specify get.

set



Usage

Use the @VirtualAccessMethods annotation to define access methods for mappings with in which accessType=VIRTUAL.


Examples

Table 2-79 shows an entity using property access.

Example 2-126 Using @VirtualAccessMethods Annotation

@Entity
  @VirtualAccessMethods
  public class Customer{
 
    @Id
    private int id;
...
 
    @Transient
    private Map<String, Object> extensions;
 
    public <T> T get(String name) {
        return (T) extensions.get(name);
    }
 
    public Object set(String name, Object value) {
        return extensions.put(name, value);
    }

In addition to using the @VirtualAccessMethods annotation, you can use the <access> and <access-method> elements in your eclipselink-orm.xml file, as shown in Example 2-127.

Example 2-127 Using <access> and <access-methods> XML

<access>VIRTUAL</access><access-methods get-method="get" set-method="set"/>@Entity


See Also

For more information, see: