I have an entity CarTransaction with 2 one-to-many compositions as list of CarDocument, one is buyerDocuments other is sellerDocuments.
These 2 lists are computed at entity level by another class CarTransactionCalculator when one property of the CarTransaction changes.
Managed to reproduce the issue in the sample project attached. If you create through editor a
CarTransaction it will properly compute 1 seller doc and 1 buyer doc.
Then save and reopen item, now sellerDocs table and buyerDocs tables display all documents.
If you look in database, there is no such duplicate, this is only in the screen.
Then by changing a letter in label field, docs are recalculated, the duplicates disappear.
I think this is related to the fact there are 2 compositions with same target entity class CarDocument in CarTransaction.
EDIT : with a bit of debugging I saw taht it happens at load time, the CarTransaction loaded is already messed up, so I think the issue is in the query/fetch. Assumption : a single join is made to load all docs but then they are not dispatched between the 2 properties sellerDocs and buyerDocs.
The properties buyerDocs and sellerDocs have no existence in the the concrete model in database. So there is only one relationship with CarDocument at this level.
I fixed that by having a single property ‘documents’ and adding an enum defining the recipient seller/buyer for the association, within CarDocument.
Which leads me to another question, I created 2 following methods in CarTransaction:
@MetaProperty
public List<CarDocument> getBuyerDocuments() {
return Collections.unmodifiableList(getDocuments().stream().filter(d->d.getRecipient() == BUYER).collect(Collectors.toList()));
}
@MetaProperty
public List<CarDocument> getSellerDocuments() {
return Collections.unmodifiableList(getDocuments().stream().filter(d->d.getRecipient() == SELLER).collect(Collectors.toList()));
}
How can I map these 2 read-only properties to 2 tables ?
I tried the following, setting 2 property data container in order to bind them to tables, but it does not work, because metaproperties are read-only.