我在使用CaseCollectionsCaseMap创建SingleCase时遇到问题。
这是我的数据库结构:
$singleCase = new SingleCase();
$singleCase->setCaActive($singleCaseDTO->getStatus());
$singleCase->setCaUrlcode($singleCaseDTO->getUrl());
$singleCase->setCaAuthorId($user->getUsrId());
$singleCase->setCaAuthorName($user->getUsrName());
$singleCase->setCaCreated();
$singleCase->setCaModified();
$this->singleCaseRepository->create($singleCase);
这是我的Doctrine ORM文件:
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "ca_id" violates not-null constraint
DETAIL: Failing row contains (null, null, /new-question, null, 0, 1, XX, 2017-12-03 13:22:18, 2017-12-03 13:22:18).
在我的CommandHandler中,我向CaseCollectionsCase repo注入了SingleCase repo。
当我只创建SingleCase时:
$defaultCollection = new CaseCollectionsCaseMap();
$defaultCollection->setCollection($cc);
$defaultCollection->setCccaPriority(0);
$singleCase->setDefaultCollection($defaultCollection);
$this->singleCaseRepository->create($singleCase);
Doctrine抛出错误:
A new entity was found through the relationship 'PPK\Domain\Entity\SingleCase\SingleCase#defaultCollection' that was not configured to cascade persist operations for entity
添加CaseCollectionsCaseMap仍然没有帮助:
An exception occurred while executing 'INSERT INTO cases (ca_id, ca_urlcode, ca_active, ca_author_id, ca_author_name, ca_modified, ca_created, ca_parent_id, ca_defaultcollection_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, "\/new-question", 0, 1, "XX", "2017-12-03 13:26:26", "2017-12-03 13:26:26", null, null]
学说抛出:
using Word = Microsoft.Office.Interop.Word;
public class Agenda {
public static void Create() {
Word.Application wordApplication = null;
Word.Document wdDocument = null;
Word.Template wdTemplate = null;
Word.BuildingBlock wdBuildingBlock = null;
object paramBBCategory = "Agenda";
object paramBBName = "Header";
try {
wordApplication = new Word.Application();
wdDocument = wordApplication.Documents.Add(Properties.Settings.Default.Template);
wdTemplate = (Word.Template)wdDocument.get_AttachedTemplate();
wdBuildingBlock = wdTemplate
.BuildingBlockTypes.Item(Word.WdBuildingBlockTypes.wdTypeQuickParts)
.Categories.Item(ref paramBBCategory)
.BuildingBlocks.Item(ref paramBBName);
wordBuildingBlock.Insert(wdDocument.Paragraphs.Last.Range);
} catch { }
}
}
当我添加级联:[" persist"," merge"]到defaultCollection doctrine throws:
{{1}}
调用persist会生成$ caId,但刷新会使其为空。
非常感谢任何帮助。
答案 0 :(得分:0)
你使用什么数据库?如果它不是MySQL,我建议您使用"AUTO"
生成策略作为您的ID。要查看哪些dbs不支持"AUTO"
策略,请参阅http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies
更新:抱歉犯了错误。如果您指定SEQUENCE
,即使它说postgres不支持AUTO
,显然仍然会使用SEQUENCE
策略。我能够从这个问题https://github.com/doctrine/doctrine2/issues/6429中找到答案。从此判断,您应该明确将ID策略设置为IDENTITY
。很抱歉早些时候误导了你。