Annotation Interface Subselect


@Target(TYPE) @Retention(RUNTIME) public @interface Subselect
Maps an immutable and read-only entity to a given SQL select expression.

For example:

 @Immutable @Entity
 @Subselect("""
            select type, sum(amount) as total, avg(amount) as average
            from details
            group by type
            """)
 @Synchronize("details")
 public class Summary {
     @Id String type;
     Double total;
     Double average;
 }
 

This is an alternative to defining a view and mapping the entity to the view using the @Table annotation.

It's possible to have an entity class which maps a table, and another entity which is defined by a @Subselect involving the same table. In this case, a stateful session is vulnerable to data aliasing effects, and it's the responsibility of client code to ensure that changes to the first entity are flushed to the database before reading the same data via the second entity. The @Synchronize annotation can help alleviate this problem, but it's an incomplete solution. We therefore recommend the use of stateless sessions in this situation.

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The subquery, written in native SQL.
  • Element Details

    • value

      String value
      The subquery, written in native SQL.