文章目录
1. JPA注解
1.1 @Entity
标注在实体类上,表示此类对应一个数据表。
1.2 @Table
与表对应,一般要与 @Entity 一起写。
@Table(name = "JPA_CUSTOMER") // 指定表名为 JPA_CUSTOMER
加 @Table 注解时,表名即为类名,通常要加。
1.3 @Id
映射数据表中的主键,该注解可以标注在属性上,也可以写在 Getter 方法上。
1.4 @GeneratedValue
- 标注主键的生成策略,通过Strategy属性指定,默认情况下 JPA 自动选择一个最适合底层数据库的主键生成策略:SqlServer 对应 identity,MySQL对应 auto increment 。
- javax.persistence.GenerationType 中定义了几