繁体   English   中英

使用@ElementCollection时出错:org.hibernate.MappingException:无法确定类型:java.util.Set,在表:对于列

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

我有两个表NewsToolSearchCriteriaNewsToolSearchCriteria_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.

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