I am fairly new to DDD. I've seen a number of example projects that use a generic AggregateId (with a String containing a GUID) as a key for an aggregate root.
I was wondering how to refer to the aggregateRoot from a child in a OneToMany relationship.
Say there is a Order AggregateRoot and a OrderLine. Would it be wise to have an extra generated (eg. sequence) id, next to the GUID, so the OrderLine can refer to that on database level? Or is the foreign key of orderLine to order the GUID ? Are there performance implications?
eg.
BaseAggregateRoot:
@MappedSuperclass
public abstract class BaseAggregateRoot {
@EmbeddedId
@AttributeOverrides({
@AttributeOverride
(name = "idValue", column = @Column(name = "aggregateId", nullable = false))
})
protected AggregateId aggregateId;
...
Order:
@Entity
public class Order extends BaseAggregateRoot{
// is this ID necessary?
@Id
@GeneratedValue(generator = "OrderSequenceGenerator")
@SequenceGenerator(name = "OrderSequenceGenerator", sequenceName = "ORD_SEQ1", allocationSize = 1)
@Column(name = "ord_seq")
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "aggregateId") <-- should this point to ID or aggregateId?
private List<OrderLine> orderLines;