![](/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.