代码之家  ›  专栏  ›  技术社区  ›  Oleksandr Stefanovskyi Adam

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

  •  0
  • Oleksandr Stefanovskyi Adam  · 技术社区  · 7 年前

    我有两张桌子 NewsToolSearchCriteria NewsToolSearchCriteria_NewsSource_Relation newsToolSearchCriteriaId 外键引用的是 NewsToolSearchCriteria (entityID)

    尝试以这种方式进行设置:

    @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;
    }
    

    但请继续接收错误:

    @Column(name = "newsSourceCode", columnDefinition = "NVARCHAR(30)") @ElementCollection(targetClass = String.class)

    我已经看到了其他类似的问题,但这不是我使用两个实体的情况,可以使用 @OneToMany

    有没有办法解决这个问题?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Сергей Стефановский    7 年前

    您只需要在getter上添加注释,而不是类参数。

    我没有找到上面写着的地方,但他们用它 documentation