Configuring Play 1.x/JPA to generate entity IDs se

2019-07-11 06:10发布

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?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-11 07:11

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.

查看更多
登录 后发表回答