Home  >  Q&A  >  body text

jpa mysql 如何id自增初始值?

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

默认是自增从1开始。

如果设置初始值自增需要使用

 @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE,generator="mySeqGenerator")
  @SequenceGenerator(name = "mySeqGenerator", sequenceName = "t_teacher_sequence", initialValue = 1000, allocationSize = 50)
  public int getId(){
    return id;
  }

但是这种sequence不支持mysql,

PHPzPHPz2743 days ago738

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:52:53

    Go directly to change the AUTO_INCREMENT value of the table

    reply
    0
  • Cancelreply