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


@Array

Use @Array to define object-relational data types supported by specific databases, such as Oracle VARRAY types or PostgreSQL JDBC Array types.


Annotation Elements

Table 2-2 describes this annotation's elements.

Table 2-2 @Array Annotation Elements

Annotation Element Description Default

databaseType

(Required) The name of the database array structure type.


targetClass

(Optional only if the collection field or property is defined using Java generics; otherwise Required) The class (basic or embeddable) that is the element type of the collection.

Parameterized type of the collection.



Usage

Use @Array on a collection attribute that is persisted to an Array type. The collection can be of basic types or embeddable class mapped using a Struct.


Examples

Example 2-5 shows how to use this annotation with an Oracle VARRAY type.

Example 2-5 Using @Array with Oracle VARRAY

VARRAY DDL:
CREATE TYPE TASKS_TYPE AS VARRAY(10) OF VARCHAR(100)
@Struct
@Entity
public class Employee {
    @Id
    private long id;
    @Array(databaseType="TASKS_TYPE")
    private List<String> tasks;
}

Example 2-6 shows how to use this annotation with an PostgreSQL Struct type.

Example 2-6 Using @Array with PostgreSQL Struct

DDL:
CREATE TABLE EMPLOYEE (ID BIGINT, TASKS TEXT[])
@Struct
@Entity
public class Employee {
    @Id
    private long id;
    @Array(databaseType="TEXT[]")
    private List<String> tasks;
}


See Also

For more information, see the following: