问题
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).
- Is this the best solution?
- Can I even do this (change my model base class) on a production website with existing data? Is this safe?
回答1:
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.
来源:https://stackoverflow.com/questions/10386189/configuring-play-1-x-jpa-to-generate-entity-ids-sequentially