Implementing Cross-datastore references for Entity User

Hi all,
I am trying to add a BusinessPartner field to the user entity. The BusinessPartner field is related to a BusinessPartner entity from a custom datastore. I followed this guide

Entities :: Jmix Documentation.

On completion, the following were added to the user entity

@SystemLevel
@Column(name = “BUSINESS_PARTNER_ID”, length = 50)
private String businessPartnerId;

@SystemLevel
@Column(name = “BUSINESS_PARTNER_ID”, length = 50)
private String businessPartnerId;

@DependsOnProperties({"businessPartnerId"})
@JmixProperty
@Transient
private BusinessPartner businessPartner;

The user-edit page is displaying the businesspartner data from the custom datastore properly
It saves the user correctly with the related businesspartnerID. When I check the user table, everything is fine. The problem I am having is that it also attempts to save all the records from the businesspartners at the same time to the custom datastore.

How can I exclude businesspartner from the fetch plan while saving. I don’t want it to save to the custom datastore. It should only save user entity. As a result of this, an error pops up when it attempts to save 27 records of the businesspartners to the custom datastore.

Hope I am able to explain myself properly.

Thanks in advance.

image

Hi @olumideo
By “custom datastore”, do you mean an additional data store which is one of the supported databases like PostgreSQL?

Hi Konstantin,
Thanks for your response. I mean the additional datastore from rest api I am getting data from.

Thanks

That’s interesting. Could you provide more detail on how your custom data store is implemented?

Hi Konstantin,
I realise that the error I am getting is related to the BusinessPartnerGroup- an association entity to the BusinessPartner entity. What I did was to remove this entity from the datastore and the error went away.

However, I still want to know if I can exclude unwanted entity from being part of the saving entity when the an entity is being saved?

Take for example:
I am trying to save a salesOrder entity, the fetchplan in the SaveContext also contains Item entity. The Item entity is not needed in savecontect, I dont know why it is included. The Item entity is a single association entity which is used in the SalesOrderLine entity- a collection association entity to SalesOrder.

My question- why is the Item entity included in the savecontext when only SalesOrder entity is needed to be saved. I don’t want saving Item entity to be triggered by the Datamanager but it always does whenever SalesOrder entity is being saved.

See the images below:

Thanks

image

The SalesOrder xml image

image

Thanks

Hi Olumide,

It’s included by DataContext because it thinks that this instance is modified.

In fact, it’s the case for any DTO entity: if you pass a DTO instance to EntityStates.isNew(), it will return true. Because unlike JPA entity, DTO entity can’t provide enough information on whether it is already stored in the database or not.

But you can provide this information. After loading data from your REST service, set the following internal flag in all instances:

for (MyDtoEntity myDto : list) {
    ((Entity) myDto).__getEntityEntry().setNew(false);
}

Then the DataContext of the screen will not consider the DTO entities modified and will not add them to SaveContext unless they are really modified in the screen.