开发者

Changing databases for a Java/Hibernate webapp

开发者 https://www.devze.com 2023-04-02 02:19 出处:网络
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:

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:

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: Duplicat开发者_StackOverflow中文版e 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'

I understand what the exceptions mean, I'm curious why they started since our app was stable on our old server (until we started to outgrow it). My questions are:

What did I mess up in this process? How can it be fixed (if it can)? How can I prevent this from happening again?

I know those are three questions, but they all stem from finding the root cause to this bug. Here's what I did:

  1. Dumped data from old database (using mysqldump).
  2. Imported data into new database (./mysql -u dbUser -p -h dbLocation dbName < localDbDumpFile.sql)
  3. 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.
  4. Dropped all tables in AWS database.
  5. Repeated steps 1 & 2 to get the latest data.
  6. 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).
  7. Launch another instance of the app on AWS Elastic Beanstalk. It pointed to the same database.

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.

For reference, here's the hibernate mapping for the object that threw the above error:

@Entity
@Table(name = "question")
public class Question implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;

Any suggestions as to why this broke, what I can do, or what I can do to prevent this from happening again would be greatly appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号