【问题标题】:when run multiple times to insert JPA Entity id gives org.springframework.dao.DataIntegrityViolationException: could not execute statement; error当多次运行以插入 JPA 实体 id 时,会给出 org.springframework.dao.DataIntegrityViolationException:无法执行语句;错误
【发布时间】:2015-09-30 13:10:24
【问题描述】:

org.springframework.dao.DataIntegrityViolationException:无法执行语句;

@Entity
@Table(name = "GROUP")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ContactGroup implements Serializable{

private static final long serialVersionUID = 7161778136151592279L;
@Id
@GenericGenerator(name = "increment", strategy = "increment")
@GeneratedValue(generator = "increment")
@Column(name = "GRP_ID")
private Long id;

}

在我的实体 id 是第一次运行时插入数据并插入 id 1 时的主键,如果我再次运行它会给出错误你能告诉我我做错了什么

【问题讨论】:

标签: java hibernate jpa spring-data-jpa


【解决方案1】:

如果您的表具有自动增量功能,可以使用

@GeneratedValue(strategy=GenerationType.IDENTITY)

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多