ORM-链接表错误

ORM-链接表错误,orm,coldfusion,coldfusion-10,Orm,Coldfusion,Coldfusion 10,我正在使用ColdBox 3.5和ColdFusion 10 Form开发一个博客应用程序,随机得到以下错误消息: 错误类型:应用程序:[N/A] 错误消息:休眠操作中出现异常。 更新/删除的行不存在,或者会话包含陈旧数据 根本原因:org.hibernate.StaleObjectStateException:行被另一个事务更新或删除,或者未保存的值映射不正确:[Entry297e1bfa369cf17501369d26ffae00a4] /型号/entry/entry.cfc: /型号/类别

我正在使用ColdBox 3.5和ColdFusion 10 Form开发一个博客应用程序,随机得到以下错误消息:

错误类型:应用程序:[N/A]

错误消息:休眠操作中出现异常。 更新/删除的行不存在,或者会话包含陈旧数据

根本原因:org.hibernate.StaleObjectStateException:行被另一个事务更新或删除,或者未保存的值映射不正确:[Entry297e1bfa369cf17501369d26ffae00a4]

/型号/entry/entry.cfc:

/型号/类别/类别.cfc:

以下是我正在运行的代码:

<cfscript>
    entry = entityNew("Entry", {
        "title" = "test",
        "body" = "test",
        "alias" = "test",
        "allowComments" = 0,
        "released" = 0,
        "user" = entityLoadByPK("User", "297e1bfa3697d377013697f53ca10084")
    });

    // works 1 out of 5 times
    entry.setCategories([entityLoadByPK("Category", "297e1bfa36986e69013698c3e54f000d")]);

    // works every time
    //entry.setCategories(entityLoad("Category", "297e1bfa36986e69013698c3e54f000d"));
    //entry.setCategories(entityLoad("Category"));

    entitySave(entry);
    ormFlush();
</cfscript>

请注意标记为works 1(共5次)和works(每次)的部分。我不明白我做错了什么。我还有其他类似的对象,它们使用链接表,我得到了类似的错误消息。我已经查看了SQL日志。当准备插入EntryCategory表时,会出现此错误。有什么想法吗?

使用HQL和where-ID-in。这很有效

如果实体已具有数组,请首先使用ArrayClear

更新:

categories = ormExecuteQuery("from Category where Id IN (:Ids)",
                             {Ids=listToArray(FORM.categoryIDs)});
entry.setCategories(categories);

entry.addCategoryentityLoadByPKCategory 297e1bfa36986e69013698c3e54f000d会更好吗?不完全是这样。我使用的维护页面设置为允许用户选择多个类别。因此,我想做的是将ID值转换为一个实体数组,然后执行entry.setCategoriesmy_category_Arrayi如果是这种情况,请使用HQL和where ID in。这很有效。如果实体已经有一个数组,那么首先使用ArrayClear。我按照你的建议做了,效果很好:Thx。你能想出我的方法不起作用的原因吗?这根本没有意义。我不确定,你可以提交一份bug报告:你能在里面放点伪代码吗。使用HQL对仅仅学习如何使用ORM的人没有多大帮助。
<cfscript>
    entry = entityNew("Entry", {
        "title" = "test",
        "body" = "test",
        "alias" = "test",
        "allowComments" = 0,
        "released" = 0,
        "user" = entityLoadByPK("User", "297e1bfa3697d377013697f53ca10084")
    });

    // works 1 out of 5 times
    entry.setCategories([entityLoadByPK("Category", "297e1bfa36986e69013698c3e54f000d")]);

    // works every time
    //entry.setCategories(entityLoad("Category", "297e1bfa36986e69013698c3e54f000d"));
    //entry.setCategories(entityLoad("Category"));

    entitySave(entry);
    ormFlush();
</cfscript>
categories = ormExecuteQuery("from Category where Id IN (:Ids)",
                             {Ids=listToArray(FORM.categoryIDs)});
entry.setCategories(categories);