Results 1 to 3 of 3

Thread: Duplicate entry for key

  1. #1
    Join Date
    Jul 2009
    Posts
    18

    Default Duplicate entry for key

    Hello,

    When i save this class.

    Code:
    @Entity
    @RooEntity
    @RooJavaBean
    @RooToString
    public class Productgroup {
    
        @NotNull
        @Size(max = 30)
        private String name;
    
        @OneToMany(cascade = CascadeType.ALL)
        private Set<Prefix> prefixes = new HashSet<Prefix>();
    
        @OneToMany(cascade = CascadeType.ALL)
        private Set<Postfix> postfixes = new HashSet<Postfix>();
    }

    I get a the following error.

    Caused by: java.sql.BatchUpdateException: Duplicate entry '1' for key 2
    at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1666)
    at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1082)
    at org.apache.commons.dbcp.DelegatingStatement.execut eBatch(DelegatingStatement.java:297)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
    ... 107 more

    This only occurs when i use hibernate with mysql not when i use openjpa with mysql. To reproduce execute the attached script, run wepapp, create some prefixes and postfixes, create two productgroups that have a relation to the same prefix or postfix.

    Kind regards,

    Ronald Vermeire
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Ronald,

    Interesting. Maybe you can switch on debug logging and SQL logging to see what different queries are being issued. That may shed some light on the issue.

    -Stefan

  3. #3
    Join Date
    Jul 2009
    Posts
    18

    Default

    Hello Stefan,

    SQL query issued is:
    insert into productgroup_postfixes (productgroup, postfixes) values (?, ?)
    .
    When i look inside the mysql db productgroup_postfixes table i see two fields eg productgroup and postfixes both are key, not null and not auto-incremented, changing those settings did not solve the problem though. Hope you can help.

    Kind regards,

    Ronald

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •