playframework / playframework/play1

Duplicate entry for key 'PRIMARY' With Play 1.5.0 + MySql

Open
#1,227 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
671
Avg merge
12d 15h
Merged PRs (30d)
1

Description

Ran into some trouble trying to upgrade 1.4.x to 1.5.0 - can't seem to find a migration guide?

After upgrading, when I save a class extending play.db.jpa.Model e.g.:

new Transaction(transDate, TransactionType.STOCK_BOUGHT, share, price, null).save();

The id of the record collides with existing entry and I get execeptions like:

Duplicate entry '9' for key 'PRIMARY'

At first it appeared to me that auto_increment of the table had been reset. But inserting manually worked fine.

Found this explanation:
https://vladmihalcea.com/why-should-not-use-the-auto-jpa-generationtype-with-mysql-and-hibernate/

Should play.db.jpa.Model be updated to use native, or should I simply make my own Model class ala:

@MappedSuperclass public class MyModel extends GenericModel { @Id @GeneratedValue( strategy= GenerationType.AUTO, generator="native" ) @GenericGenerator( name = "native", strategy = "native" ) public Long id; ...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with play.db.jpa.Model and the GenericModel inheritance shown in the report, then inspect the @GeneratedValue mapping used for ids. Reproduce the duplicate-primary-key save with MySQL while comparing Play 1.5.0 against 1.4.x. Done means the cause is confirmed and the supported mapping or migration guidance is documented with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mysql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.