2
votes

I was reading Implementing Domain-Driven Design by Vaughn Vernon and in the chapter about aggregates the following structure is shown:

enter image description here

This structure can be mapping easily using Hibernate/NHibernate as the each entity references the aggregate root by reference.

However, he decides to refactor the design to this:

enter image description here

Now all entities reference the root using the ProductId value object instead.

How can one model this using Hibernate/NHibernate?

The explanation for the diagrams can be found here Effective Aggregate Design by Vaughn Vernon

2
Not sure why to do so but a simple Map(x => x.ProductId) or Component(x => x.ProductId, c => c.Map(...)) would suffice no?Firo
@Firo I added a link for the explanation for the diagrams.Songo

2 Answers

0
votes

In hbms of BacklogItem, Rlease, Sprint

<component name="productId">
    <property name="value" column="product_id"/>
</component>

Or in JPA style

@Embedded
@OverrideAttributes....
private ProductId productId

In this case, the BacklogItem doesn't need to lazyload the Product, so a simple identifier is enough. Just treat them as hibernate components.

0
votes

with (Fluent-)NHibernate it would look like

Component(x => x.ProductId, c => c.Map(pid => pid.Value, "product_id"));