gihan-maduranga
gihan-maduranga

Reputation: 4811

How to compare hibernate BO objects using Javers

My requirement is that For application audit purposes i want to compare two BO objects and return a obj diff as a Json string to store details into audit table.To compare objects i have chosen Javers. in my case i have implemented a hibernate interceptor that will monitor the BO actions.That part works fine.But when try to compare BO objects with Javers throw me a error called

ENTITY_INSTANCE_WITH_NULL_ID: Found Entity instance 'com.myproject.runtime.bo.Result_$$_jvstc5f_5' with null idProperty 'resultid'

Here is my sample hibernate Result class

class Result {

    @id //javax.persistence.Id
    resultid;
    name;
    etc ...
    }

Obj comparison code snippet

public static <B> String compareObjDiff(final B oldBo, final B newBo) {

        Javers javers = JaversBuilder.javers().build();

        Diff diff = javers.compare(oldBo, newBo);
        return javers.getJsonConverter().toJson(diff);
    }

Please let me know how can i compare hibernate BO objects using javers.also is it possible to ignore @id property?

Note:Bo object can contains null values in runtime.

Upvotes: 1

Views: 778

Answers (1)

Bartek Walacik
Bartek Walacik

Reputation: 3496

I'm not sure what is Hibernate BO object. If you mean domain objects (entities being persisted by Hibernate) -- the answer is in this question Javers ENTITY_INSTANCE_WITH_NULL_ID when using 2 databases

Upvotes: 2

Related Questions