0

I'm trying to test pojo classess using openpojo but i have the same error like there. I don't understand that solution so I'll ask again. What should I do to proper using @BusinessKey.

My classes:

public class Person {
    @BusinessKey
    private Integer id;

...getters/setters

    @Override
    public boolean equals(Object obj) {
        return BusinessIdentity.areEqual(this, obj);
    }

    @Override
    public int hashCode() {
        return BusinessIdentity.getHashCode(this);
    }
} 


public class Employee {
    @BusinessKey
    private Integer id;

    private Person person;

    ...getters/setters

    @Override
    public boolean equals(Object obj) {
        return BusinessIdentity.areEqual(this, obj);
    }

    @Override
    public int hashCode() {
        return BusinessIdentity.getHashCode(this);
    }
}
Community
  • 1
  • 1
Kacper
  • 1,000
  • 2
  • 10
  • 18

1 Answers1

0

The @BusinessKey annotation is designed to be thrown on your business keys, not your generated database ids. So to annotate the fields, you have ask the business, what makes a person a person? how can two "Person" objects be determined to be the same? This should be done in the context of the business and how it identifies what makes a person a person.

In the example above, for Employee I am guessing you can't have a valid Employee object without it being linked to a person, so the @BusinessKey needs to be on person (plus other important fields).

Hope this helps.

Osman Shoukry
  • 294
  • 2
  • 6