JPA- basic annotation

1. @Entity: marked on the entity class, the entity class indicating that the Java class mapped to the specified database table;

@Entitypublic class DeptEntity {}

2. @Table: When an entity class mapping table name is not the same, need to use this annotation annotation, the annotation and @Entity used in parallel:

  "Name: name of the table specified database;

  "Schema: the user specifies the name of the database;

@Entity
@Table(name = "dept", schema = "yootk")
public class DeptEntity {}

3. @Id: declare a primary key column, can be stated on the property, it can also be stated on the get method

4. @GeneratedValue: Strategies for generating a primary key are denoted, strategy specified by attributes, default, JPA automatically selects a suitable implementation strategy underlying database

  "Strategy specify the policy:

    GenerationType.IDENTITY: id increment, oracle does not support

    GenerationType.AUTO: automatically selects the appropriate strategy

    GenerationType.SEQUENCE: generating a primary key by sequence designated by the sequence name @SequenceGenerator () annotations, MySql does not support

    GenerationType.TABLE: primary key generated by the table frame by means of the primary key table pattern generating sequence, using the strategy more portable database

@Entity
@Table(name = "dept", schema = "yootk")
public class DeptEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long deptno;
}

5. @Basic: indicates that the property to map the fields of the database table, the default is @Basic, you can not write

  "Fetch: represents the read policy for the property, there are EAGER and LAZY two types represent the main branch crawl and delayed loading, the default is EAGER.
  " Optional: indicates that the property is allowed to be null, the default is true

6. @Column: When a different name column of the database table mapping attributes of the entity and its need to use, when the field names are the same, you can not write

    @Basic
    @Column(name = "dname")
    private String dname;

7. @Transient: indicates that the property is not mapped to a field in a database table, ORM framework will ignore the property, if the property is not a field mapping database tables, be sure to mark it as @Transient, otherwise, ORM framework of its default annotated as @Basic

    @Transient
    private Double avgsal;

 

Guess you like

Origin www.cnblogs.com/luliang888/p/11267353.html