我不知道如何设置初始值@GenerateValue
@Id
.
我尝试过使用GenerationType.SEQUENCE
但这是不允许的MySQL
。如何设置用于的初始值@GenerateValue
?
两者同时使用AUTO
and TABLE
我仍然无法获得开始的初始值,但1
谢谢
Code使用自动
@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() {
}
}
使用表的代码
@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() {
}
}
** 更新 **
该问题与未设置 hibernate.id.new_generator_mappings=true 有关;
https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html
Spring Boot 的 Application.properties:
spring.jpa.properties.hibernate.id.new_generator_mappings=true