JPA annotations are commonly used default abstract methods inherited methods and keywords

A, JPA annotations in common:

1, @ Entity: a class name tag in the above, as the identity of the entity class;

2, @ Table: When a table name and its mapped entity class are not the same need @Table label instructions,

  Before the label and labeling @Entity used in parallel, placed in the entity class declaration statement can be written in a separate statement lines,

  You can walk with declaration statement.

  @Table marked common options are name, used to indicate the name of the database table.

  There is also a marked @Table two options catalog and schema for the database directory or mode setting table belongs,

  Usually the database name. uniqueConstraints option to set constraints, usually not be provided;

3, @ Id: represents the object identifier is provided, the primary key attribute mapping entity class identifier in the correspondence table;

4, @ GeneratedValue: Set Identifier generation strategy is often used in conjunction with @Id.

  Parameters: strategy specifies the specific generation strategy:

  Method 1: @GeneratedValue (strategy = GenerationType.AUTO) is the default strategy,

       That can also be written as @GeneratedValue; similar to the native strategy to hibernate,

      Generated depends on the underlying database.

  方式二:@GeneratedValue(strategy = GenerationType.IDENTITY)
      Specify "auto-grow" strategy for MySQL;
  方式三:@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “seqtblperson”)
      Specify "sequence" strategy, commonly used in Oracle, which represents the generator name generator. But also specified
      @SequenceGenerator(name=“seqtblperson”, sequenceName=“seqtblperson”, allocationSize=1)
      Notes used in conjunction. Wherein the name specifies the name of the generator (the same as the value of the generator),
      sequenceName specify the name defined in the database sequences, allocationSize the specified sequence each increase of 1.
5, @ Column: database table defined in the description field, has the following properties.
  (1) name: indicates the name of the database table field, the default situation is consistent attribute name.
  (2) nullable: This field indicates whether to allow null, the default is true.
  (3) unique: Indicates whether the field is a unique identifier, the default is false.
  (4) length: indicates the size of the field, the field is valid only for type String.
  (5) insertable: said in ORM frame insertion operation, whether the field should appear INSETRT statements, the default is true.
  (6) updateable: ORM framework, said in an update operation, whether the field should appear in the UPDATE statement, the default is true. For the field once created can not be changed, the property is useful, such as for birthday field.
  (7) columnDefinition: represents the actual type of the field in the database. Typically ORM framework may 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, the default mapping of type String VARCHAR, if you want to String types are mapped to BLOB or TEXT field types for a particular database, the property is very useful.
  (8) @OrderBy: when loading the data sequence can be assigned.
  (9) @Transient: This attribute indicates not mapped to a field in a database table, ORM framework will ignore the attributes. If a property is not a field mapping database tables. Be sure to mark it as @Transient. otherwise. ORM framework annotated as its default @Basic
Second, the default inherited methods:
  1, Spring Data JPA a sub - Spring Data technology, the JPA Spring Data used to access the data only needs the data access interface layer can JpaRepository interfaces. JpaRepository interface extends PagingAndSortingRepository, QueryByExampleExecutor interface, so have their CRUD operations functions.
  2, conventional interface methods:
  

 

 Third, the keyword abstract methods:

  1, the method naming convention:

    (1) conditional attribute conditions connected by keyword.

    The first letter (2) Conditions property must be capitalized.

  2, named and explained the case:

  

  (1) And - and the equivalent SQL keywords, such as findByUsernameAndPassword (String user, Striang pwd) Find a user name and password. 

  (2) Or - equivalent to or keyword in SQL, such as findByUsernameOrAddress (String user, String addr) Find the user name or address;

  (3) Between - equivalent to between keywords in SQL, such findBySalaryBetween (int max, int min) between the query and pay the max min; 

  (4) LessThan - SQL equivalent of "<", such findBySalaryLessThan (int max); 

  (5) GreaterThan - equivalent to the SQL ">", such findBySalaryGreaterThan (int min);

  (6) IsNull - equivalent to the SQL "is null", such findByUsernameIsNull (); 

  (7) IsNotNull - equivalent to the SQL "is not null", such findByUsernameIsNotNull (); 

  (8) NotNull - and IsNotNull equivalence;

  (9) Like - SQL equivalent of "like", such findByUsernameLike (String user); 

  (10) NotLike - SQL equivalent of "not like", such findByUsernameNotLike (String user); 

  (11) OrderBy - equivalent to the SQL "order by", such findByUsernameOrderBySalaryAsc (String user); 

  (12) Not - equivalent to the SQL, such findByUsernameNot (String user); "=!"

  (13) In - SQL equivalent of "in", such findByUsernameIn (Collection userList), the parameter type Collection method may be, or may be an array variable length parameter; 

  (14) NotIn - SQL equivalent of "not in", such findByUsernameNotIn (Collection userList), the parameter type Collection method may be, or may be an array variable length parameter; 

 

 

Guess you like

Origin www.cnblogs.com/szcy/p/12594290.html