spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Support logical fields(method @Column)

Open DreamStar92 opened this issue 1 year ago • 3 comments

Supporting methods as write-only fields, the current implementation causes confusion when using properties because the field value is a placeholder.

Or are there other correct ways to implement logical fields that I don’t know? Please let me know.

expect

    public class Rectangle {

        private int h;
        private int w;

        @Column
        public int area() {
            return h * w;
        }

    }

current

    public class Rectangle {

        private int h;
        private int w;
        @AccessType(AccessType.Type.PROPERTY)
        private int area;
        
        public int getArea() {
            return h * w;
        }

    }

DreamStar92 avatar Jul 12 '24 12:07 DreamStar92

The write only property would at the very least be constructed as a normal getter:

public int area() {
    return h * w;
}

That said, it doesn't work either. :-/

schauder avatar Jul 15 '24 12:07 schauder

This should work fine with just the annotations, and should not require special forms of method names.

Currently, even if it is a normal getter, it will not take effect if there is no field.

DreamStar92 avatar Jul 16 '24 06:07 DreamStar92

Methods in embedded objects should also support write-only fields, and also support prefixes.

Is there any current plan for this enhancement? @schauder

At present, the processing of some calculated properties is very tricky and very error-prone, because if the fields that the calculated properties depend on change, the fields of the calculated properties must be reassigned. If forgotten, it will be catastrophic. If you use @AccessType(AccessType.Type.PROPERTY), Instead of reassigning a computed property field each time, accidentally using a field instead of a getter method would be disastrous.

DreamStar92 avatar Dec 11 '24 14:12 DreamStar92