spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
753 stars 345 forks source link

Support logical fields(method @Column) #1835

Open DreamStar92 opened 1 month ago

DreamStar92 commented 1 month ago

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;
        }

    }
schauder commented 1 month ago

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. :-/

DreamStar92 commented 1 month ago

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.