gpt4 book ai didi

java - 为什么这个序列生成器不在 Spring Boot 中创建数据库表?

转载 作者:行者123 更新时间:2023-11-29 06:00:01 25 4
gpt4 key购买 nike

@Entity
@Table(name = "addition_type")
public class AdditionType {
@Id
@SequenceGenerator(name = "addition_type_id_seq", sequenceName = "addition_type_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "addition_type_id_seq")
@Column(name = "id")
private int id;

@Column(name = "code")
private String code;

@Column(name = "name")
private String name;

@Column(name = "sinhala_name")
private String sinhalaName;

@Column(name = "report_name")
private String reportName;

@Column(name = "status")
private int status;

@ManyToOne
@JoinColumn(referencedColumnName = "id")
private CompanyInfo companyInfo;

// there are not show getter and setter
}

当我在 Spring 中使用这个类时,生成了两个数据库表:AdditionType实体表,以及 addition_type_id_seq序列生成器对应的表。 AdditionType表有列:id、name、code ...,另一个表有 next valueid .

当我在 Spring Boot 中使用此类时,它并没有像那样创建两个表。只有 AdditionType表已创建。为什么是SequenceGenerator无法在 Spring Boot 中工作?

最佳答案

由于 MYSQL 方言不支持序列:

我们可以使用表生成器策略来定义序列:

    @Id
@TableGenerator(name = "addition_type_id_seq", allocationSize = 1, table = "ADDITION_TYPE_SEQUENCES",
pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_NUMBER",
pkColumnValue = "SEQUENCE")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "addition_type_id_seq")
@Column(name = "id")
private int id;

这将确保创建两个表:ADDITION_TYPE_SEQUENCES 和 ADDITION_TYPE

关于java - 为什么这个序列生成器不在 Spring Boot 中创建数据库表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45778038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com