0

I am trying to Implement OneToOne Relationship bw 3 entities but facing this hashcode related error. I have 3 classes in 2 classes i am trying access that one entity.

sakshi
  • 1
  • 3

2 Answers2

0

The problem is not with CompanyAccessRights but with that both:

  • Company contains reference to CompanyEmploymentSettings and
  • CompanyEmploymentSettings contains reference to Company

The lomboks @EqualsAndHashCode is calculating the hashcode by calling the hashCode() method on all the complex type fields, so the problem is that CompanyEmploymentSettings.hashCode() is calling the Company.hashCode() and then the Company.hashCode() is calling the CompanyEmploymentSettings.hashCode() and again, and again, until you use all the stack memory - the StackOverflowException.

To fix this, you can remove one of those fields or you can mark these fields with @EqualsAndHashCode.Exclude to exclude this field in hashCode calculations

dey
  • 3,022
  • 1
  • 15
  • 25
0

Try using fetch = FetchType.LAZY for @OneToOne relationship;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "company_access_rights")
private  CompanyAccessRights companyAccessRights;

Hope it can solve your problem.

Phil Ku
  • 191
  • 1
  • 6