views:

30

answers:

2

In the sample DDD project written by Eric Evans (http://domaindrivendesign.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?

+1  A: 

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).

Arnis L.