在JPA实体中添加auto_increment

时间:2019-02-07 11:21:32

标签: java jpa spring-data-jpa entity jpa-2.0

我将这个实体定义用于JPA:

@Entity
@Table(name = "payment_transactions")
public class PaymentTransactions implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, updatable = false, nullable = false)
    private int id;

    @Column
    private Date date;

    @Column
    private Integer year;
    .....
    }

表已成功创建:

CREATE TABLE `payment_transactions` (
  `id` int(11) NOT NULL,
  ....
  PRIMARY KEY (`id`),
}

表已成功创建。

但是我希望MariaDB自动生成唯一的表键值。像这样:

CREATE TABLE `payment_transactions` (
  `id` int(11) NOT NULL auto_increment,
  ....
  PRIMARY KEY (`id`),
}

使用JPA进行配置的正确方法是什么?

0 个答案:

没有答案