Skip to content

DbJsonB immediately dirty on load if multiple enum as property #3129

@AntoineDuComptoirDesPharmacies

Description

Hi everyone,

We are having a strange behavior with DbJsonB feature on POJO where multiple properties are Enum.
Ebean Version : 13.20.1

Expected behavior

Having an entity A with a DbJsonB property composed of a POJO B with multiple fields (each fields is an enum).
After DB/find.byId of entity A , DB.beanState should answer that the entity is not dirty.

Actual behavior

Having an entity A with a DbJsonB property composed of a POJO B with multiple fields (each fields is an enum).
After DB/find.byId of entity A , DB.beanState answer that the entity is dirty on the DbJsonB property even without change.

Steps to reproduce

@Entity
public class A{
    [...]
    @DbJsonB
    @Column(nullable = false)
    private A.B sources;
    [...]

    @JsonInclude(JsonInclude.Include.NON_NULL) // Do not encode null to "null" to gain space in DB
    static public class B {
        private DataProviderEnum field1;
        private DataProviderEnum field2;

        public B() {
           // NOTHING TO DO
        }

        @JsonCreator
        public B(
                @JsonProperty("field1") DataProviderEnum field1,
                @JsonProperty("field2") DataProviderEnum field2
                                   ) {
            this.field1= field1;
            this.field2 = field2;
        }


        public DataProviderEnum getField1() {
            return field1;
        }

        public void setField1(DataProviderEnum field1) {
            this.field1= field1;
        }

        public DataProviderEnum getField2() {
            return field2;
        }

        public void setField2(DataProviderEnum field2) {
            this.field2= field2;
        }

        @Override
        public String toString() {
            return "ProductFieldSources{" +
                    "field1=" + field1+
                    ", field2=" + field2+
                    '}';
        }
    }
}

public enum DataProviderEnum {
    @EnumValue("VALUE1")
    VALUE1,
    @EnumValue("VALUE2")
    VALUE2,
    @EnumValue("VALUE3")
    VALUE3
}

Here is the value for this property in database :

{"field1": "VALUE1", "field2": "VALUE2"}

When executing :
DB.beanState(A.find.byId(1L)).dirtyValues()
If mutationDetection = SOURCE :
=> Return the property sources with Old being null and New being the value from database.

If mutationDetection = DEFAULT :
=> Return the property sources with Old and New value being the same (value from database) but with different object reference.

Important note :

  • If I replace DataProviderEnum by String type, the problem disappear
  • If I delete one of the field from database, (eg. : {"field1": "VALUE1"}), then the problem disappear
  • Even if the second field have no meaning with the schema, the problem stay (eg. : {"field1": "VALUE1", "any": "blue"})

Thanks in advance for your help.
Yours faithfully,
LCDP

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions