Java entitymanager中存在重复密钥错误,要保留的对象正确

Java entitymanager中存在重复密钥错误,要保留的对象正确,java,jpa,eclipselink,derby,entitymanager,Java,Jpa,Eclipselink,Derby,Entitymanager,我有以下实体标题Creeformat,当我执行entitymanager.commit时 我发现以下错误 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 i

我有以下实体标题Creeformat,当我执行
entitymanager.commit时
我发现以下错误

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 'SQL130418144233630' defined on 'S1_TITLESCREENFORMAT'. Error Code:
20000 Call: INSERT INTO s1_TitleScreenFormat
(titlescreenformat_titleid, titlescreenformat_format,
titlescreenformat_deliveryformat, TITLE_title_id) VALUES (?, ?, ?, ?)
    bind => [TitleId1, Format1, DeliveryFormat1, null]
这是带有键的实体

@Entity
    @Table(name = "s1_TitleScreenFormat")
    public class TitleScreenFormat 
    {
        @Id 
        @Column(name = "titlescreenformat_titleid", length = 128)    
        private String TitleId;

        @Id 
        @Column(name = "titlescreenformat_deliveryformat", length = 128)    
        private String DeliveryFormat;

        @Id 
        @Column(name = "titlescreenformat_format", length = 128)    
        private String Format;


        private Title Title;
这就是我想要保存的对象的实例

[0] TitleScreenFormat  (id=81)  
    DeliveryFormat  "DeliveryFormat1" (id=87)   
    Format  "Format1" (id=88)   
    Title   null    
    TitleId "TitleId1" (id=89)  
[1] TitleScreenFormat  (id=83)  
    DeliveryFormat  "DeliveryFormat2" (id=90)   
    Format  "Format2" (id=91)   
    Title   null    
    TitleId "TitleId2" (id=92)  
[2] TitleScreenFormat  (id=84)  
    DeliveryFormat  "DeliveryFormat3" (id=93)   
    Format  "Format3" (id=94)   
    Title   null    
    TitleId "TitleId3" (id=95)  
[3] TitleScreenFormat  (id=85)  
    DeliveryFormat  "DeliveryFormat4" (id=96)   
    Format  "Format4" (id=97)   
    Title   null    
    TitleId "TitleId4" (id=98)  
[4] TitleScreenFormat  (id=86)  
    DeliveryFormat  "DeliveryFormat5" (id=99)   
    Format  "Format5" (id=100)  
    Title   null    
    TitleId "TitleId5" (id=101)
在persistence.xml文件中,我使用以下配置

<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />

我正在使用Derby数据库


出现此错误的原因可能是什么?

我认为您再次在数据库中插入相同的值。 在持久化这些值之前,只要在数据库中检查一次,如果它们已经存在的话


或者,您可以更改这些值,然后再次尝试提交。

但是drop和create表应该每次都会创建新实例……您不这么认为吗?您是在glassfish这样的服务器上部署应用程序吗?如果是这样,Glassfish将截取EclipseLink DDL属性并使用其自己的Java2DB功能,因此请检查创建的脚本和日志,以查看是否按预期正确删除了表。启用日志记录,并检查是否正在删除和创建表,并且没有发生重复插入。