问题描述
为具有给定名称的特定序列生成 nextval 的最简单方法是什么?
What would be the easiest way to generate nextval for some particular sequence with given name?
带指定的注解方案
* @ORMGeneratedValue(strategy="SEQUENCE")
* @ORMSequenceGenerator(sequenceName="sq_foobar", allocationSize="1", initialValue="1")
不满足我,只要涉及一些更复杂的逻辑:在某些情况下我需要检索 nextval,在其他情况下 - 我会使用从其他来源检索的值(不是顺序).
doesn't satisfy me, as long as there is some more complex logic involved: in some cases I need to retrieve nextval, in other - I would go with the value retrieved from another sources (not sequence).
所以我希望有一种方法可以在实体的构造函数中手动检索序列 nextval.
So I hope there is a way to retrieve a sequence nextval manually in entity's constructor.
推荐答案
那么我认为你应该实现自己的 Identitfer Generator.
Then I think you should implement your own Identitfer Generator.
最简单的方法是覆盖 DoctrineORMIdSequenceGenerator 类来处理您的特定情况.
The easyest would be to override the DoctrineORMIdSequenceGenerator class to handle your specific case.
然后,您必须使用 Doctrine ORM API 在类元数据中注册此生成器.
You then have to register this generator in the class metadata using Doctrine ORM API.
一些链接:http://ranskills.wordpress.com/2011/05/26/how-to-add-a-custom-id-generation-strategy-to-doctrine-2-1/
https://github.com/doctrine/doctrine2/pull/206
这篇关于在 Doctrine 2 中手动生成下一个序列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)