ripper234
ripper234

Reputation: 230048

Configuring Play 1.x/JPA to generate entity IDs sequentially?

What's the best way to force Play/JPA to make entity IDs sequential? (They are not)

One idea is to copy play.db.jpa.Model into my own ModelBase class and change the generation strategy to GenerationType.IDENTITY (at least for mysql).

  1. Is this the best solution?
  2. Can I even do this (change my model base class) on a production website with existing data? Is this safe?

Upvotes: 2

Views: 127

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

If you need a pure sequence (no gaps) for your entities, don't use the id, create a new sequence in your database and link it to an extra field in your model.

It will be simpler and save you headaches when compared to trying to force the ID to have no gaps.

Upvotes: 3

Related Questions