gpt4 book ai didi

java - 使用EntityManager在derby DB中保留实体会产生java.sql.SQLIntegrityConstraintViolationException

转载 作者:行者123 更新时间:2023-12-02 09:46:22 26 4
gpt4 key购买 nike

当我尝试在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对象,但是发生了以下错误。请告诉我我做错了什么?

最佳答案

这对TestSearchs有帮助吗?

@GeneratedValue(strategy = GenerationType.TABLE)

关于java - 使用EntityManager在derby DB中保留实体会产生java.sql.SQLIntegrityConstraintViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com