DDD 并使用 Hibernate 在数据库中存储复杂的值对象

发布于 2024-09-11 07:01:16 字数 586 浏览 3 评论 0原文

在 Eric Evans 编写的示例 DDD 项目 (http://dddcommunity.org/examples) 中,有一个 Cargo class 是一个实体对象,并使用 hibernate 映射到数据库表。该 Cargo 域对象由多个值对象组成,其中之一是 Delivery。此交付值对象非常复杂,因为它有大约 10 个字段。尽管如此,Delivery 是一个平面对象,因此它可以完美地将自己存储在与 Cargo 相同的表中的数据库中。

我在我的应用程序中遵循了埃文斯的例子,但我遇到了一些困难,希望你能帮助我。

我有一个 InvoiceDefinition 实体对象,它是一个聚合根。除此之外,它还有一个 InvoiceLine 类型的字段,它是一个值对象。 InvoiceLine 不能独立于 InvoiceDefinition 而存在。诀窍在于 InvoiceLine 可以是叶节点或具有子 InvoiceLine 值列表的树节点。这样就形成了一个递归结构。

这可以作为有效的值对象传递吗? 如何使用hibernate在数据库中存储这样的值对象?

In the sample DDD project written by Eric Evans (http://dddcommunity.org/examples) there is a Cargo class which is an entity object and is mapped to db table using hibernate. That Cargo domain object consists of several value objects one of which is Delivery. This Delivery value object is quite complex as it has some 10 fields. Nonetheless Delivery is a flat object so it renders itself perfectly to be stored in db in the same table as Cargo is.

I've followed Evans example in my app but I arrived at some difficuties and hope you could help me out.

I have an InvoiceDefinition entity object, which is an aggregate root. Among other things it has a field of InvoiceLine type, which is a value object. InvoiceLine cannot exist in isolation from InvoiceDefinition. The trick is that InvoiceLine can be either a leaf or a tree node with a list of child InvoiceLine values. So it forms a recursive structure.

Can this pass as a valid value object?
How to store such a value object in db using hibernate?

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

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

发布评论

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

评论(1

撩心不撩汉 2024-09-18 07:01:16

我认为如果值对象是一个复合,那没有什么不好。
但不变性可能存在问题。

据我所知 - 使用 hibernate 映射复合材料有点棘手(这里是 nhibernate 的教程)。

I think that there's nothing bad if value object is a composite.
There might be problems with immutability though.

As far as i know - mapping composites using hibernate is a bit tricky (here's a tutorial for nhibernate).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文