Hi, thank you for the example.
There are two errors in your code:
1) The "country" string should not be annotated as @IndexedEmbedded, but as @Field
Code:
private int id;
@ContainedIn
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "companyId", nullable = false)
private Company company;
@IndexedEmbedded // Make this @Field instead
private String country;
2) you forgot to add the facilities to the set of facilities of the company
The CompanyFacility constructors should be:
Code:
public Companyfacility() {
}
public Companyfacility(Company company,String country) {
this.company = company;
this.country = country;
company.getCompanyfacilities().add( this );
}
When dealing with relations in Hibernate, always make sure you update both directions of the relation:
Companyfacility.company
AND
Company.companyfacilities