Annotation Interface FieldResult


@Target({}) @Retention(RUNTIME) public @interface FieldResult
Used in conjunction with the EntityResult annotation to map a column specified in the SELECT list of a SQL query to a property or field of an entity class.

The name() member specifies the name of the mapped field or property of the entity class. If the property or field is declared by a child embeddable object, then name() specifies a qualified path.

Consider the following SQL query:

Query orders =
        em.createNativeQuery(
            """
               SELECT o.id AS order_id,
                      o.quantity AS order_quantity,
                      o.item AS order_item
               FROM Order o
               WHERE o.quantity > 25
            """,
            ResultMappings_.MAPPING_ORDERS
        );

The result set mapping might be defined as follows:

@SqlResultSetMapping(
    name = "Orders",
    entities = @EntityResult(
         entityClass = Order.class,
         fields = {
             @FieldResult(name = Order_.ID,
                          column = "order_id"),
             @FieldResult(name = Order_.QUANTITY,
                          column = "order_quantity"),
             @FieldResult(name = Order_.ITEM,
                          column = "order_item")
        }
    )
)
interface ResultMappings {}

At runtime, a FieldResult annotation is represented by an instance of FieldMapping in the ResultSetMapping returned by EntityManagerFactory.getResultSetMappings(Class).

Since:
1.0
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Name of the column in the SELECT clause—that is, the column alias, if applicable.
    Name of the persistent field or property of an entity class.
  • Element Details

    • name

      String name
      Name of the persistent field or property of an entity class.
    • column

      String column
      Name of the column in the SELECT clause—that is, the column alias, if applicable.