Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging databases for a Java/Hibernate webapp
    primarykey
    data
    text
    <p>I recently moved a Java webapp (using hibernate) from a CentOS 5.5 to AWS Elastic Beanstalk / RDS. At some point, it started generating exceptions:</p> <pre><code>Sep 1, 2011 6:53:20 PM org.hibernate.util.JDBCExceptionReporter logExceptions WARNING: SQL Error: 1062, SQLState: 23000 Sep 1, 2011 6:53:20 PM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: Duplicate entry '318297-69699' for key 'PRIMARY' Sep 1, 2011 6:53:20 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions SEVERE: Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: could not insert collection: [com.iengage.objects.business.SlideManagementBO.students#318297] ... Caused by: java.sql.BatchUpdateException: Duplicate entry '318297-69699' for key 'PRIMARY' </code></pre> <p>I understand what the exceptions mean, I'm curious <em>why</em> they started since our app was stable on our old server (until we started to outgrow it). My questions are: </p> <p>What did I mess up in this process? How can it be fixed (if it can)? How can I prevent this from happening again?</p> <p>I know those are three questions, but they all stem from finding the root cause to this bug. Here's what I did:</p> <ol> <li>Dumped data from old database (using mysqldump).</li> <li>Imported data into new database (./mysql -u dbUser -p -h dbLocation dbName &lt; localDbDumpFile.sql)</li> <li>Uploaded .war file to beanstalk. Only changes were to db properties (host, name, password). At this point everything seemed to be working well. Logs looked clear (although I can't say I did an exhaustive search). At this point, this was still a test server, but everything looked good, so we decided to make the switch.</li> <li>Dropped all tables in AWS database.</li> <li>Repeated steps 1 &amp; 2 to get the latest data.</li> <li>Launched, everything looked good. Notice the first (that I noticed that is) primary key error in logs two days later- thought it was interesting and I should check it out later (regretting that one now).</li> <li>Launch another instance of the app on AWS Elastic Beanstalk. It pointed to the same database.</li> </ol> <p>This is where I was when I started noticing the errors. They seem to be accelerating, and I'm thinking of switching back to the old server, but if my mistake was in the way I transferred the DB data, I don't want to repeat the error. </p> <p>For reference, here's the hibernate mapping for the object that threw the above error:</p> <pre><code>@Entity @Table(name = "question") public class Question implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") private Integer id; </code></pre> <p>Any suggestions as to why this broke, what I can do, or what I can do to prevent this from happening again would be <strong>greatly</strong> appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload