AttributeAccessService implementation doesn't work well with new entities

Hi, we use attribute setup attribute access handlers which set access based on some entity’s attributes values, e.g. an entity can have a property with a list of some other ones, which form the ground to alter accees to the attributes. AttributeAccessService uses merge on all entities, including new ones. After that operation some fields become empty (I think it’s normal behaviour for merge on new entity) and handler couldn’t process setup correctly. What was the reason to use merge here for new entites? /cc @knstvk

@Override
    public SecurityState computeSecurityState(Entity entity) {
        Preconditions.checkNotNullArgument(entity, "entity is null");

        SecurityState state;
        String storeName = metadataTools.getStoreName(metadata.getClassNN(entity.getClass()));
        Transaction tx = persistence.createTransaction(storeName);
        try {
            EntityManager em = persistence.getEntityManager(storeName);
            Entity managedEntity = em.merge(entity);
            support.setupAttributeAccess(managedEntity);
            state = BaseEntityInternalAccess.getSecurityState(managedEntity);
            // do not commit the transaction
        } finally {
            tx.end();
        }
        return state;
    }

BR,
Ilia Rodionov

Hi Ilia,

Thank you for the hint. We’ll consider to not merge new instances in this case, see the issue.

You can correct the behavior of AttributeAccessServiceBean by overriding it in your project. Use EntityStates to check if the passed instance is new.

Regards,
Konstantin