配置Play 1.x / JPA按顺序生成实体ID? [英] Configuring Play 1.x/JPA to generate entity IDs sequentially?

查看:162
本文介绍了配置Play 1.x / JPA按顺序生成实体ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

强制Play / JPA使实体ID顺序的最佳方法是什么? (不是



一个想法是将play.db.jpa.Model复制到我自己的 ModelBase 类中,并将生成策略更改为 GenerationType.IDENTITY (至少对于mysql)。


  1. 这是最好的解决方案吗?

  2. 即使在生产网站上使用现有数据做到这一点(更改我的模型基类)?这是安全的吗?如果您的实体需要一个纯粹的序列(无间隙) ,不要使用该id,在数据库中创建一个新的序列并将其链接到模型中的一个额外字段。



    与强迫ID没有差距相比,它会更简单并且让你头疼。


    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?

    解决方案

    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.

    这篇关于配置Play 1.x / JPA按顺序生成实体ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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