JPA之@Entity、@Table、@Column、@Id、@GeneratedValue、@Basic

@Entity show class (userEntity) as an entity class, which corresponds to the default database table name is user_entity. Here can also be written
      @Entity (name = "xwj_user")
      or
      @Entity
      the @Table (name = "xwj_user", Schema = "Test")

See @Entity annotation, found that there is only one attribute name, the table name indicates its corresponding database
      
@Table : when different entity class name of the database table name mapped thereto requires @Table explanatory notes, and the callout annotation @Entity prior to use in parallel, placed in the entity class declaration statement can be written in a separate statement lines, but also with peers declaration statement.
      @Table annotation common options are name, name of the table specified in the database
      @Table notes there are two options catalog and schema for the database directory or mode setting table belongs, usually the database name

@Column : when a different database table column name attribute mapping entity requires its @Column label instructions, this property is usually placed before the entity attribute declaration statement, and may also be used with labeled @Id.
@Column (insertable = false, updatable =

@Column marked common properties be name, or for setting a mapping database table column name. In addition, the label further comprises a plurality of additional attributes, such as: unique, nullable, length and the like.

@Column marked columnDefinition properties: indicates the actual type of the field in the database generally ORM framework can automatically determine the type of attribute type fields in the database, but is still unable to determine the type for the Date field type database whether DATE, TIME, or TIMESTAMP. in addition, String default mapping type is VARCHAR, BLOB or TEXT field types for a particular database if you want to map to the String type.

Before @Column labeling methods may also be placed getter properties

@Id : annotation for declaring an attribute mapping entity class is a primary key column of the database. This property is usually placed before the property declaration, with declaration counterparts, can also be written on a separate line. Before labeling @Id attribute getter method may be disposed.

@GeneratedValue : the meaning of existence as an entity annotation is mainly to generate a primary key to uniquely identify and label generation strategy for the primary key, attributes specified by the strategy. @GeneratedValue annotation has two attributes, namely strategy, and generator
default, JPA automatically selecting a primary key generation strategy best suited to the underlying database:
strategy properties: provides four values:

IDENTITY: self ID database using growth increasing manner from the primary key field, Oracle does not support this approach; (corresponding to SqlServer)

AUTO: JPA automatically choose the right strategy is the default option; (MySQL correspondence)

SEQUENCE: generated by the primary key sequence, the sequence name specified by @SequenceGenerator notes, MySql does not support this approach

TABLE: generating a primary key table by the frame by means of the primary key table to produce the analog sequences, the policy may make it easier to apply database migration.

@Basic represents a simple property mapping database table field, marked for no getXXXX () method, that is, the default

@Basic 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

Published 14 original articles · won praise 4 · Views 246

Guess you like

Origin blog.csdn.net/Red_rose9/article/details/105280657