DDD population identifiers and foreign keys

I am new to DDD. I saw several sample projects that use a common AggregateId (with a String containing a GUID) as the key for the aggregate root.

I was wondering how to relate to aggregateRoot from a child in a OneToMany relationship.

Say that there is an aggregation order and an order order. It would be wise to have an additional generated (e.g. sequence) id next to the GUID, so can OrderLine refer to this at the database level? Or an OrderLine foreign key to order a GUID? Are there any implications for work?

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;
+3
source share
1 answer

-, , DDD - , , . , . , ( ) , , . . , , .

, GUID . GUID . GUID. :

Sequential Guid ?

. , GUID .

, . . , - GUID . , , . @Id Long id. , @EmbeddedId @Column.

, ,

.

+1

All Articles