I can not figure out how to set the initial value for the @GenerateValue @Id.
I have tried using GenerationType.SEQUENCE but that is not allowed in MySQL. How can I set the initial value to be used for the @GenerateValue?
Using both AUTO and TABLE I can still not get the initial value to start at anything but 1
Thank you
Code using AUTO
@Entity
@Data
@SequenceGenerator(name = "port_gen", sequenceName = "port_gen", initialValue = 4700)
public class AppiumPort {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "port_gen")
private Long port;
public AppiumPort() {
}
}
Code using TABLE
@Entity
@Data
public class AppiumPort {
@TableGenerator(name = "Address_Gen", table = "ID_GEN", pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL", pkColumnValue = "Addr_Gen", initialValue = 10000, allocationSize = 100)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "Address_Gen")
private int port;
public AppiumPort() {
}
}
** UPDATE **
The problem was related to not setting hibernate.id.new_generator_mappings=true;
Application.properties for Sring Boot:
spring.jpa.properties.hibernate.id.new_generator_mappings=true
解决方案
You could try and use the @TableGenerator (JPA has a @TableGenerator annotation in which you can set an initial value). The initialValue can be used to seed the values