问题
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