JPA @Id and @GeneratedValue @Table explanatory notes

@Id annotation for declaring an attribute mapping entity class 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.
@GeneratedValue:
General mysql database auto-increment primary keys @GeneratedValue (at Strategy = GenerationType.IDENTITY)
(1), the meaning of existence @ GeneratedValue notes mainly as an entity to generate a primary key that uniquely identifies, @ GeneratedValue provides primary key generation strategy.

(2), @ GeneratedValue annotation has two attributes, namely strategy and Generator,
Generator properties:

generator属性的值是一个字符串,默认为"",其声明了主键生成器的名称
(对应于同名的主键生成器@SequenceGenerator和@TableGenerator)。

property strategy: provide four values:

-AUTO主键由程序控制, 是默认选项 ,不设置就是这个
 
-IDENTITY 主键由数据库生成, 采用数据库自增长, Oracle不支持这种方式
 
-SEQUENCE 通过数据库的序列产生主键, MYSQL  不支持
 
-Table 提供特定的数据库产生主键, 该方式更有利于数据库的移植

Note: The default @GeneratedValue does not require additional parameters, but if the database control increment primary key (AUTO_INCREMENT), no parameters will be given
@GeneratedValue (strategy = GenerationType.IDENTITY) If mybatis InsertOrUpdate using the
ON DUPLICATE KEY UPDATE time to add this comment on the corresponding entity class

@Table annotation indicates that the entity at the corresponding database table
these annotations are javax.persistence package inside

Published 80 original articles · won praise 140 · views 640 000 +

Guess you like

Origin blog.csdn.net/linjpg/article/details/99876573