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.
Asked
Active
Viewed 121 times
2 Answers
0
The problem is not with CompanyAccessRights
but with that both:
Company
contains reference toCompanyEmploymentSettings
andCompanyEmploymentSettings
contains reference toCompany
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