我不知道如何设置@GenerateValue
@Id
的初始值。如何在Spring JPA for MySQL中为@Id @GeneratedValue设置初始值?
我已经尝试过使用GenerationType.SEQUENCE
但这不允许在MySQL
。我如何设置@GenerateValue
的初始值?
同时使用AUTO
和TABLE
我仍然不能得到初始值的任何东西,但1
开始感谢您使用表
代码使用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() {
}
}
代码
@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
Application.properties为SRING引导:
spring.jpa.properties.hibernate.id.new_generator_mappings=true
如果你设置分贝自己,你可以做到这一点你的mysql数据库中,如果它不使用JPA/ORM产生的,它只是映射,而无需实际创建数据库。 – Sarief
我试着用MySQL数据库上的表生成器,它完美的工作。但我没有用过春天。 – ujulu