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


@Struct

Use @Struct to define a class to map to a database Struct type. The class should normally be an Embeddable, but could also be an Entity if stored in a object table.


Annotation Elements

Table 2-64 describes this annotation's elements.

Table 2-64 @Struct Annotation Elements

Annotation Element Description Default

name

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


fields

(Optional) Defines the order of the fields contained in the database structure type.




Usage

Struct types are extended object-relational data-types supported by some databases. Struct types are user define types in the database such as OBJECT types on Oracle. Structs normally contain Arrays (VARRAY) or other Struct types, and can be stored in a column or a table.

You can also use Struct types to call PL/SQL stored procedures that use RECORD types in an Oracle Database.


Examples

Example 2-103 shows using the @Struct annotation to define a Java class to map to an OBJECT type.

Example 2-103 Using @Struct Annotation

@Embeddable
@Struct(name="EMP_TYPE", fields={"F_NAME", "L_NAME", "SALARY"})
public class Employee {
 @Column(name="F_NAME")
 private String firstName;
 @Column(name="L_NAME")
 private String lastName;
 @Column(name="SALARY")
 private BigDecimal salary;
 ...
}

Example 2-104 shows how to use the <struct> element in the eclipselink-orm.xml file.

Example 2-104 Using <struct> XML

<embeddable class="Address" access="FIELD">
  <struct name="PLSQL_P_PLSQL_ADDRESS_REC">
    <field>ADDRESS_ID</field>
    <field>STREET_NUM</field>
    <field>STREET</field>
    <field>CITY</field>
    <field>STATE</field>
  </struct>
  <attributes>
    <basic name="id">
      <column name="ADDRESS_ID"/>
    </basic>
    <basic name="number">
      <column name="STREET_NUM"/>
    </basic>
  </attributes>
</embeddable>


See Also

For more information, see: