Stef
Stef

Reputation: 2683

How to make Javers compare by field values rather than ID/object reference

I have an object like:

class Person {
    Phone phone;
}

class Phone {
    String number;
    String prefix;
    Phone(String n, String p) {
        number = n;
        prefix = p;
    }
}

Now consider this code:

Person p = new Person();
p.phone = new Phone("444444", "01");
javers.commit(p);
p.phone = new Phone("555555", "01");
javers.commit(p);

In this case sees that the reference of Phone has changed. While that's good info, I don't really care about that. I just want to know when the value of the number field has changed, that's really what I am tracking.

How would I achieve that? I tried defining the Phone class as a ValueObject, but it doesn't seem to do the job, I still get it as reference change rather than value change in the resulting Commit snapshot. Should I register it as a Value instead?

Upvotes: 0

Views: 813

Answers (1)

Bartek Walacik
Bartek Walacik

Reputation: 3496

Map Phone as ValueObject or let JaVers to apply default mapping, which is also ValueObject object. ValueObject are always compared property by property and never by reference. What do you mean by it doesn't seem to do the job?

Upvotes: 1

Related Questions