1

我有以下实体 TitleScreenFormat,当我这样做时,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 DB。

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

4

1 回答 1

0

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

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

于 2013-04-19T09:08:14.373 回答