Reputation: 380
I have two tables NewsToolSearchCriteria
and NewsToolSearchCriteria_NewsSource_Relation
.
newsToolSearchCriteriaId
is the foreign key references to NewsToolSearchCriteria (entityID)
I want to see a set of elements from the second table inside first.
Trying to set it up this way:
@ElementCollection
@CollectionTable(name = "NewsToolSearchCriteria_NewsSource_Relation", joinColumns = @JoinColumn(name = "newsToolSearchCriteriaId"))
@Column(name = "newsSourceCode")
private Set<String> newsSources;
public Set<String> getNewsSources() {
return newsSources;
}
public void setNewsSources(Set<String> newsSources) {
this.newsSources = newsSources;
}
But keep receiving the error:
nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: dbo.NewsToolSearchCriteria, for columns: [org.hibernate.mapping.Column(newsSources)]
I've already tried to use @Column(name = "newsSourceCode", columnDefinition = "NVARCHAR(30)")
and @ElementCollection(targetClass = String.class)
I already saw other similar questions but it is not the case where I using two entities and it could be resolved using@OneToMany
.
Any ideas how to resolve this issue?
Upvotes: 0
Views: 2002
Reputation: 36
You just have to add annotations on getter instead of a class parameter.
I did not find the place where it said, but they use it in documentation and it works for me.
Upvotes: 2