![](/img/trans.png)
[英]Getting a org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Authors after using @ElementCollection
[英]Error while using @ElementCollection: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: for columns
我有兩個表NewsToolSearchCriteria
和NewsToolSearchCriteria_NewsSource_Relation
。 newsToolSearchCriteriaId
是對NewsToolSearchCriteria (entityID)
newsToolSearchCriteriaId
)的外鍵引用,我想從第二個表中首先看到一組元素。
嘗試通過以下方式進行設置:
@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;
}
但是繼續收到錯誤:
嵌套的異常是org.hibernate.MappingException:無法確定類型:java.util.Set,在表:dbo.NewsToolSearchCriteria,對於列:[org.hibernate.mapping.Column(newsSources)]
我已經嘗試使用@Column(name = "newsSourceCode", columnDefinition = "NVARCHAR(30)")
和@ElementCollection(targetClass = String.class)
我已經看到了其他類似的問題,但不是使用兩個實體的情況,可以使用@OneToMany
來解決。
任何想法如何解決這個問題?
您只需要在getter上添加注釋,而不是類參數即可。
我沒有找到它說的地方,但他們在文檔中使用了它,對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.