Annotation Interface Entity


@Target(TYPE) @Retention(RUNTIME) public @interface Entity
Indicates an entity class.

The entity class represents a database relation (table or SQL result set). An instance of the class represents a row.

The entity class can be defined as either mutable or immutable.

The mutable entity:

 @Entity
 public class Employee {

     @Id
     @Column(name = "ID")
     Integer id;

     @Column(name = "EMPLOYEE_NAME")
     String employeeName;

     @Version
     @Column(name = "VERSION")
     int version;

     ...
 }
 
The immutable entity:
 @Entity(immutable = true)
 public class Employee {

     @Id
     @Column(name = "ID")
     final Integer id;

     @Column(name = "EMPLOYEE_NAME")
     final String employeeName;

     @Version
     @Column(name = "VERSION")
     final int version;

     public Employee(Integer id, String employeeName, int version) {
         this.id = id;
         this.employeeName = employeeName;
         this.version = version;
     }
     ...
 }
 

The entity instance is not required to be thread safe.

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether the entity class is immutable.
    The entity listener class.
    The metamodel information for the Criteria API.
    The naming convention that maps the entity class to the database table.
  • Element Details

    • listener

      Class<? extends EntityListener> listener
      The entity listener class.

      If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class.

      An instance of the entity listener class is instantiated only once per entity class.

      Returns:
      the entity listener class
      Default:
      org.seasar.doma.jdbc.entity.NullEntityListener.class
    • naming

      NamingType naming
      The naming convention that maps the entity class to the database table.

      If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class.

      Returns:
      the naming convention
      Default:
      NONE
    • immutable

      boolean immutable
      Whether the entity class is immutable.

      If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class. The values must be consistent in the hierarchy.

      If not specified and the entity class is a record, the class is recognized as immutable even though this value is false.

      Returns:
      whether the entity class is immutable
      Default:
      false
    • metamodel

      Metamodel metamodel
      The metamodel information for the Criteria API.

      If specified, the metamodel class is generated by the annotation processor.

      Returns:
      the metamodel
      Default:
      @org.seasar.doma.Metamodel