Play framework, inserting initial-data more than 20 items per one Model

好久不见. 提交于 2020-01-05 10:07:08

问题


In the development mode of Play framework, I inserted my initial-data.yml through Global.java. However, if one model has more than 20 items, autu-generated IDs is going crazy.

For example, if I had:

computers:
- !!models.Computer
    name: apple01
- !!models.Computer
    name: apple02
- !!models.Computer
    name: apple03
- !!models.Computer
    name: apple04
       ...
- !!models.Computer
    name: apple20
- !!models.Computer
    name: apple21
- !!models.Computer
    name: apple22

From 1 to 20, they got correct auto-generated IDs by the order that I inserted. However, after 20, I could not get IDs that I intended. For example, the auto-generated ID of an item whose name is 'apple22' is 34. It's weird. Is there anyone who knows why this happens?


回答1:


I expect it's batched fetching of sequences (section 10) and multiple threads/connections but there isn't enough info in the question to tell.

However a more useful answer might be to ask - why do you care? Being gappy doesn't mean incorrect. Sequentially generated IDs like this should be internal opaque identifiers used only for joins and integrity and suchlike. Don't depend on them being time ordered or non gappy, and don't expose your application to them. If you need a key field with specific characteristics, you're best off defining another one.



来源:https://stackoverflow.com/questions/11932111/play-framework-inserting-initial-data-more-than-20-items-per-one-model

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