大桌子亲子

发布于 2024-10-06 08:44:36 字数 237 浏览 0 评论 0原文

如果我有像categoryA这样的pojo ->子类别A-->书本关系。 子类别 A 是父类别 A 的子类别。书是子类别A的子类别 所有内容都位于同一实体组内

在这种情况下,如果我需要将“书籍”移动到另一个子类别 B,则 。我需要删除subcategoryA和categoryA,并重新创建categoryA ->子类别A-->没有书?并重新创建categoryb ->子类别b-->书,其他书,其他书3?

if have i have pojo like categoryA -> subcategoryA--> book relationship.
subcategoryA is child of parent categoryA. book is child of subcategoryA
in this case, everything is inside same entitygroup

if i need to move 'book' to another subcategory-B. i need to delete subcategoryA and categoryA, and recreate categoryA -> subcategoryA--> without book ? and recreate categoryb -> subcategoryb--> book ,other-book, other-book3 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-10-13 08:44:36

如果“book is child of subcategoryA”并且您通过将 subcategoryA 的键添加到 book 的键路径来对此进行建模,则您需要删除/重新创建 book,或者需要使用与 subcatagoryA 最初具有的键相同的键创建 subcatagoryB。这将影响属于子类别 A 子类别的所有其他书籍。

这是因为(引用 appengine 文档:“在数据存储中创建实体时分配完整的键,并且其任何部分都不能更改。”)。

对我来说,这两种解决方案似乎都非常棘手,我建议您重新考虑您的设计。例如,您可以将 subcatagoryA 的键存储为单独属性内的单独字段。这也有缺点,您可以通过对数据进行非规范化并将子类别 A 的(部分)数据直接存储在书中来部分解决。

[编辑]

回答你的问题:小型实体组的缺点是不能使用事务。这是否是一个问题取决于...您是否真的需要书籍+((子)类别上的交易。当您想要更改非规范化数据的某些内容时,就会出现更大的非规范化问题。为此,您可以提出一个像这样的方案:

  • 将每个类别存储为具有属性的实体。将类别 KEY +(一些)其他属性与您的书籍一起存储
  • 如果类别发生更改,则更新属于该类别的所有书籍的所有非规范化数据。存储的“外键”来查找这些书籍)
  • 使用 cron 作业来检查后台的一致性(即前一个作业中途失败的情况)。

If 'book is child of subcategoryA' and you have modeled this by adding subcategoryA's key to book's key-path, you either need to delete/recreate book, or you need to create a subcatagoryB with the same key as subcatagoryA originally had. This would affect all other books that were child of subcatagoryA.

This is because (citing appengine docs: "The complete key is assigned when the entity is created in the datastore, and none of its parts can change.").

Both solutions to me seem as quite tricky, and I suggest that you rethink your design. For instance, you could store subcatagoryA's key as a seperate field inside a separate property. This has down-sides as well, which you could partly solve by denormalizing your data and storing (part of) subcatagoryA's data directly INSIDE book.

[EDIT]

In response to your question: the disadvantage of small entity groups is that you can not use transactions. Whether this is a problem depends on...whether you really need transactions on books+((sub)categories. A bigger problem of denormalization comes up when you want to change something of your denormalized data. For this, you could come up with a scheme like this:

  • store each category as an entity with properties. Store the category KEY + (some of) the other properties with your book(s).
  • If a category changes, update all denormalized data of all books belonging to that category (used stored 'foreign' key to find these books)
  • Use a cron job to check for consistency in the background (ie for cases where the previous job fails mid-way).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文