2015年2月24日 星期二

[Bug] javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [Model Name#index]

出現此Bug為在persistence中有已有一個Primary key相同的物件存在
若該Primary key為自動累加的流水號
需在JPA特別設定
@GeneratedValue(strategy=GenerationType.IDENTITY)

如下:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id",length = 15)
private Integer id;

沒有留言:

張貼留言