Entity annotation processor - field access not intercepted?

Hi,
I notice that my entity is not being marked dirty when I assign a property a value from within the class.
Im assuming this is due to the annotation processor enriching getter/setter but not field access.

Let me clarify with an example
I have a one-to-many relationship Parent - Child.

A child can be well-behaved or not. I have an action button that toggles the wellBehaved attribute in the UI. After pressing the button I call a method countWellBehavedChildrenon the Parent class that counts the well-behaved children and updates an integer with the correct value.

When I update the integer from within that method, my entity is not being marked dirty in the views datacontext. If from within that method I call the setter, then it is being marked dirty.

Is this by design, or just overlooked?

    class Parent {
        List<Child> children;
        Integer numberOfWellBehavedChildren;

        void setNumberOfWellBehavedChildren(int number) {
            this.numberOfWellBehavedChildren = number;
        }

        void countWellBehavedChildren() {
            numberOfWellBehavedChildren = 0;
            int wellBehavedChildrenCounter = 0;
            
            
            for (Child child : children) {
                if (child.isWellBehaved) {
                    numberOfWellBehavedChildren++; // does not work, I assume because there is no proxy
                    wellBehavedChildrenCounter++;
                }
                setNumberOfWellBehavedChildren(wellBehavedChildrenCounter); //this works, because I'm passing the value through a method that is proxied
            }
        }

    }
    class Child {
        boolean isWellBehaved;
    }

Would be nice to get a reply on this one. Is this a bug?

Hello!

Sorry for the late reply

Yes, as in the general case for JPA entities in Jmix, bypassing the setters results in changes not being tracked.

Regards,
Dmitry

1 Like