[英]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
. 我有两个表
NewsToolSearchCriteria
和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. newsToolSearchCriteriaId
是对NewsToolSearchCriteria (entityID)
newsToolSearchCriteriaId
)的外键引用,我想从第二个表中首先看到一组元素。
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)]
嵌套的异常是org.hibernate.MappingException:无法确定类型:java.util.Set,在表:dbo.NewsToolSearchCriteria,对于列:[org.hibernate.mapping.Column(newsSources)]
I've already tried to use @Column(name = "newsSourceCode", columnDefinition = "NVARCHAR(30)")
and @ElementCollection(targetClass = String.class)
我已经尝试使用
@Column(name = "newsSourceCode", columnDefinition = "NVARCHAR(30)")
和@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
. 我已经看到了其他类似的问题,但不是使用两个实体的情况,可以使用
@OneToMany
来解决。
Any ideas how to resolve this issue? 任何想法如何解决这个问题?
You just have to add annotations on getter instead of a class parameter. 您只需要在getter上添加注释,而不是类参数即可。
I did not find the place where it said, but they use it in documentation and it works for me. 我没有找到它说的地方,但他们在文档中使用了它,对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.