Announcement Announcement Module
Collapse
No announcement yet.
Duplicate entry for key Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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

    Comment


    • #3
      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

      Comment

      Working...
      X