nextval使用给定名称生成某些特定序列的最简单方法是什么?
带指定的注释解决方案
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="sq_foobar", allocationSize="1", initialValue="1")
Run Code Online (Sandbox Code Playgroud)
不满足我,只要涉及一些更复杂的逻辑:在某些情况下我需要检索nextval,在其他情况下 - 我会使用从其他来源(不是序列)检索的值.
所以我希望有一种方法可以在实体的构造函数中手动检索序列nextval.
在doctrine2中,我有一个实体,它具有从Web服务中获取的主键,并且还有一个应该是自动增量的索引.
我可以在mysql中手动设置,但不能在doctrine2中使这个工作.
zend-framework primary-key auto-increment symfony doctrine-orm
我正在尝试检索id值vtiger_crmentity_seq,以便更新,vtiger_crmentity.crmid因为它不是auto_increment
所以这是我的实体 vtiger_crmentity
/**
* @var integer
*
* @ORM\Column(name="crmid", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="vtiger_crmentity_seq", allocationSize=1, initialValue=1)
*/
private $crmid;
/**
* Get crmid
*
* @return integer
*/
public function getCrmid()
{
return $this->crmid;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试提交表单时,Symfony2会返回此错误.
平台不支持"Doctrine\DBAL\Platforms\AbstractPlatform :: getSequenceNextValSQL"操作.500内部服务器错误 - DBALException
我无法改变vtiger_crmentity.crmid,auto_increment所以这个想法被放弃了,我也需要更新vtiger_crmentity_seq.id到显然使用的最新值...