Skip to content

Unexpected dirty checking behavior on collections of POJOs mapped with JsonBinaryType #138

Closed
@mojgh

Description

Description

When reading entities with collections of POJOs such as TestEntity (see Example 1), updates are performed on the database without the objects being changed.

Example 1

@TypeDefs({
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@Entity
public class TestEntity {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    public int id;

    @Type(type = "jsonb")
    public Collection<TestElement> testElements;


    public static class TestElement implements Serializable {

        static final long serialVersionUID = -8485895696327472738L;

        public String testProperty;

    }

}

Analysis

It appears as if the dirty check on JsonBinaryType properties for collections of POJOs does no longer work as expected.
The problem occurs since [commit-1]. This commit introduces a new dirty checking behavior for JsonBinaryType, when used with collections:

public boolean areEqual(Object one, Object another) {
// ...
	if (one instanceof Collection && another instanceof Collection) {
		return Objects.equals(one, another);
	}

JsonTypeDescriptor

I would not expect the usage of java.lang.Object#equals at this point. In my understanding it creates an inconsistency compared to the dirty checking behavior used for non-collection types.
The recursive field by field comparison before [commit-1] is appropriate in my opinion.

Workaround

Downgrade to the version before [commit-1]: version 2.4.2.

Links

commit-1

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions