Soft References for Entities addon breaks entity export via JSON and SQL

Hi,

i just found out that when the addon GitHub - mariodavid/cuba-component-entity-soft-reference: CUBA component that allows reference any entities with soft references is used in an entity, this breaks the functionality of the entity export in the entity inspector as well as “System Information” > “Insert Script” information.

Basically the data that is used in the soft-reference attribute is not correct. Unfortunately this leads to the fact that the entity export for this entity is broken completely.

Attached you’ll find an example project.

cuba-problem-entity-soft-reference-export.zip (108.7 KB)

Here is an example exported JSON:

[
  {
    "_entityName": "cpesre$Order",
    "id": "d3f1575f-d0ea-6cef-31d1-7200ea634461",
    "createdBy": "admin",
    "createTs": "2018-07-05 18:43:22.638",
    "version": 1,
    "updateTs": "2018-07-05 18:43:22.638",
    "orderDate": "2018-07-05",
    "customer": "Fry" // <<-- this is wrong. Expected value might be "cpesre$Customer-7034a7c6-5211-2c42-ec54-e06226f5103a"
  }
]

Here’s the broken SQL:

insert into CPESRE_CUSTOMER
(ID, VERSION, CREATE_TS, CREATED_BY, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, NAME)
values ('7034a7c6-5211-2c42-ec54-e06226f5103a', 2, '2018-07-05 18:36:50', 'admin', '2018-07-05 18:38:02', 'admin', null, null, 'Fry');


insert into CPESRE_ORDER
(ID, VERSION, CREATE_TS, CREATED_BY, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, ORDER_DATE, CUSTOMER)
values ('483f86b6-842c-7be3-4b7d-26f6bf9ac1bc', 1, '2018-07-05 18:36:51', 'admin', '2018-07-05 18:36:51', null, null, null, '2018-07-05', '7034a7c6-5211-2c42-ec54-e06226f5103a');

-- this is also wrong. It should be "cpesre$Customer-7034a7c6-5211-2c42-ec54-e06226f5103a" for ORDER.CUSTOMER

Do you have any idea what is the root cause of this behavior?

Bye
Mario

I forgot to add the EntitySoftReferenceConverter in the example. However, it does not change anything at the problem…

Here’s the updated version:
cuba-problem-entity-soft-reference-export.zip (98.3 KB)

I just hit this issue. It is very unfortunate. JSON exporting/importing is very important to my workflow. And this issue not only impacts the Soft Reference add on but also some other valuable add ons: Taggable and Attachable, which use soft references.

And the User Inbox add on! :cry:

Hi,

You are right. This problem still exists and is also quite problematic, because it is the underpinning of a lot of my plugins.

I did not yet do further analysis on it though on platform side. Perhaps someone has an idea?

Bye
Mario

Hi,

I took a look why the JSON serialization prints it wrongly into the file. I have narrowed the problem to the range definition of the metaProperty. Here’s one example:

The Tagging entity holds a soft-reference to the “taggable” - which is any kind of Entity.

In this line: cuba-component-taggable/Tagging.java at master · mariodavid/cuba-component-taggable · GitHub
I further defined the metaproperty and specified the datatype.

In the entity serialization: cuba/EntitySerialization.java at master · cuba-platform/cuba · GitHub there is a switch for different kinds: datatypes, classes / entities, Enum etc. The taggable property gets classified as a datatype. With that it calls the format method of the custom datatype: cuba-component-entity-soft-reference/EntitySoftReferenceDatatype.java at master · mariodavid/cuba-component-entity-soft-reference · GitHub

The problem is, that needs a different representation based on the use case.

For JSON the representation I want the representation to be ceut$Customer-cbad1747-00c5-7bcd-1abc-f197edd85ee3 while for the UI related parts I want the representation to be different: Customer 123.

Currently the output is optimized towards the UI because it shows the instance name (cuba-component-entity-soft-reference/EntitySoftReferenceDatatype.java at master · mariodavid/cuba-component-entity-soft-reference · GitHub).

This most likely also is true for the Excel export functionality.

Is there any change on differentiating between those two? In the code I currently don’t see anything framework wise which would allow me to do that.

The alternative would be to just stick to the EntityLoadInfo representation and live with the UI being a little strage (at least entity inspector & excel export) - but I did not checked it out yet.

hi,

the issue is solved with version 0.5.0 of the entity-soft-reference addon.

bye
Mario