How to register changes to related entities

Hi,

I have two entities. The first one is the regular Customer entity, e.g.:

    @NotNull
    @Column(name = "name", nullable = false)
    private String name;

    @Composition
    @OneToOne(mappedBy = "Id")
    private Order order;

The other is the Order entity, that is related 1:1 to Customer.

How to register changes made to the Order entity. I.e. whenever changes are made to the Order entity, the Listener for Customers does not receive the event that Customer has been changed (as it should, but what needs to be implemented so that when the Order attributes are changed, the Customer will also be notified that one of its attributes (i.e. Order) has been changed)?

Hi,

There is no such functionality - to notify Customer about changing of related Order.

Instead, you should:

  • implement an EntityChangedEvent listener for the Order entity,
  • in the event handler load associated Customer objects by executing a query with TransactionalDataManager.
  • and then execute associated logic with customer.

See detailed example in the developer’s manual: EntityChangedEvent - CUBA Platform. Developer’s Manual

1 Like