当多次运行时插入JPA实体id给出了org.springframework.dao.DataIntegrityViolationException:无法执行语句;错误

时间:2015-09-30 13:10:24

标签: java hibernate jpa spring-data-jpa

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,如果我再次运行它会给出错误你能告诉我我错了什么

1 个答案:

答案 0 :(得分:0)

如果你的桌子有自动增量,可以使用

@GeneratedValue(strategy=GenerationType.IDENTITY)