当我尝试在Derby DB中使用Entitymanger持久化对象时,我收到以下错误: -
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL150318192139760' defined on 'TESTSEARCHS '.
Error Code: 20000
Call: INSERT INTO TESTSEARCHS (SEARCHID) VALUES (?)
bind => [1 parameter bound]
Query: InsertObjectQuery(example.com.TestSearchs@4e049f)
相关代码是: -
public class TestA extends SuperA{
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
protected TestSearchs testSearchs;
........
}
SuperA类提供TestA的ID
@Entity
@XmlTransient
@MappedSuperclass
@Inheritance(strategy = InheritanceType.JOINED)
public class SuperA{
@Id
private String id;
.........
}
并且TestSearchs类是: -
public class TestSearchs {
@Id
@GeneratedValue
@XmlTransient
private long searchId;
@ElementCollection(targetClass = String.class,fetch = FetchType.EAGER)
protected List<String> testsearch=new ArrayList<String>();
.....
}
我通过调用TestA的setter来设置Id,这是唯一的,然后我使用entityManager.Persit()来持久化TestA对象,但发生以下错误。请告诉我我做错了什么?
答案 0 :(得分:0)
这对TestSearchs有帮助吗?
@GeneratedValue(strategy = GenerationType.TABLE)