简体   繁体   中英

Error while using @ElementCollection: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: for columns

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM