PL-8759 Error on saving edit screen with composition if it contains a single datasource for reference to master entity

This commit is contained in:
Konstantin Krivopustov 2017-03-07 17:27:55 +04:00
parent 79fec7cad2
commit adc838627d

View File

@ -340,16 +340,20 @@ public class DsContextImpl implements DsContextImplementation {
MetaProperty metaProperty = datasource.getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
if (inverseProp != null && !inverseProp.getRange().getCardinality().isMany()) {
MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(inverseProp.getDomain());
if (metaClass.equals(datasource.getMetaClass())
&& (PersistenceHelper.isLoaded(entity, inverseProp.getName())
&& entity.getValue(inverseProp.getName()) != null)) // replace master only if it's already set
{
Object masterItem;
Object masterItem = null;
if (masterDs instanceof CollectionDatasource) {
Object id = ((Entity) entity.getValue(inverseProp.getName())).getId();
masterItem = ((CollectionDatasource) masterDs).getItem(id);
Entity value = entity.getValue(inverseProp.getName());
if (value != null) {
Object id = value.getId();
//noinspection unchecked
masterItem = ((CollectionDatasource) masterDs).getItem(id);
}
} else {
masterItem = masterDs.getItem();
}