primary key configuration
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cust_id")
private Long custId;//主键
- @Id: Indicates that this annotation indicates that this attribute corresponds to the primary key in the data table
- @GeneratedValue(strategy = GenerationType.IDENTITY)
This annotation indicates the generation strategy of configuring the primary key, similar to auto-increment in mysql.
strategy indicates the strategy used by this annotation, you can use GenerationType.IDENTITY, GenerationType.SEQUENCE, GenerationType.TABLE, GenerationType.AUTO.
GenerationType.IDENTITY: The underlying database must support auto-growth, (similar to mysql auto-increment)
GenerationType.SEQUENCE: The underlying database must support sequences, (Oracle)
GenerationType.TABLE: A mechanism provided by jpa to help complete primary key auto-increment in the form of a data table
GenerationType.AUTO: The program automatically selects the appropriate primary key generation strategy