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

大城市里の小女人 提交于 2019-12-11 02:45:46

问题


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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!