播放框架,每个模型插入初始数据超过20个项目 [英] Play framework, inserting initial-data more than 20 items per one Model

查看:82
本文介绍了播放框架,每个模型插入初始数据超过20个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Play框架的开发模式中,我通过Global.java插入了initial-data.yml.但是,如果一个模型有20多个项目,则由autu生成的ID会变得疯狂.

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.

例如,如果我有:

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

从1到20,他们按照我插入的顺序获得了正确的自动生成的ID.但是,20岁以后,我无法获得想要的ID.例如,名称为"apple22"的商品的自动生成的ID为34.这很奇怪.有谁知道为什么会这样吗?

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?

推荐答案

我希望它是已批处理(第10节)和多个线程/连接,但问题中没有足够的信息可以说明.

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.

但是,可能有一个更有用的答案是-您为什么在乎?变得空洞并不意味着不正确.这样的顺序生成的ID应该是内部不透明标识符,仅用于连接和完整性等.不要依赖于他们按时间顺序排列或毫无生气,也不要将应用程序暴露给他们.如果您需要一个具有特定特征的关键字段,则最好定义另一个字段.

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.

这篇关于播放框架,每个模型插入初始数据超过20个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆