Page 1 of 1

Delete does not work for AdminPresentationCollection

Posted: Wed Oct 08, 2014 1:35 am
by jay.rajani
Hi,

I have created a custom entity Merchant. The business requirement is that a merchant can define its child merchants and a merchant can also define its parent merchant.

I have created following mapping in domain class

Code: Select all

@ManyToOne(targetEntity = MerchantImpl.class, optional = true)
    @Cascade(value={org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "PARENT_MERCHANT_ID")
    @AdminPresentation(friendlyName = "Parent Merchant", tab = "Merchant Information", fieldType = SupportedFieldType.FOREIGN_KEY,
            validationConfigurations={
                    @ValidationConfiguration(validationImplementation="parentMerchantValidator",
                            configurationItems={
                                    @ConfigurationItem(itemName=ConfigurationItem.ERROR_MESSAGE, itemValue="Parent can not be a child of other merchant")
                            })
            })
    @AdminPresentationToOneLookup(lookupDisplayProperty = "name")
    private Merchant parentMerchant;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = MerchantImpl.class, mappedBy="parentMerchant")
    @Cascade(value={org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements")
    @BatchSize(size = 50)
    @AdminPresentationCollection(friendlyName="Child Merchants", tab = "Child Merchants", tabOrder = 10, addType = AddMethodType.LOOKUP,
            operationTypes = @AdminPresentationOperationTypes(removeType = OperationType.NONDESTRUCTIVEREMOVE))
    protected List<Merchant> childMerchants = new ArrayList<Merchant>();


I see proper UI. I am also able to add child merchants using child merchants tab. But when I select a child merchant and delete it. It does not get deleted from list. As per requirements, we dont want to delete the merchant but the association should be removed.

I check BasicPersistenceModule.remove() method call, the item removed is successfully removed from list

Code: Select all

if (SupportedFieldType.FOREIGN_KEY == ((BasicFieldMetadata) mergedProperties.get(originalPropertyName)).getFieldType()) {
                            String value = property.getValue();
                            Serializable foreignInstance = persistenceManager.getDynamicEntityDao().retrieve(Class.forName(foreignKey.getForeignKeyClass()), Long.valueOf(value));
                            Collection collection = (Collection) fieldManager.getFieldValue(foreignInstance, foreignKey.getOriginatingField());
                            collection.remove(instance);
                            break;
                        }


I also see "saved" message on list but it does not get removed. Any idea how I can resolve this ?

Regards,
Jay Rajani