Java 后台程序出现 A different object with the same identifier value 报错

一个可能的原因是数据库使用了id自增做主键,但是插入两个数据的时候,使用了相同的id;

比如,如果使用了JPA,需要加上下面的代码:

    @Id
    @GeneratedValue(strategy = IDENTITY)

    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

你可能感兴趣的:(Java 后台程序出现 A different object with the same identifier value 报错)