【问题标题】:Create relation between an entity and non-entity objects在实体和非实体对象之间创建关系
【发布时间】:2011-12-22 14:54:03
【问题描述】:

我的 webapp 中有一些名为 Site 的域对象。 站点将包含 IP 地址列表,即

@Entity
class Site {

    ...

    @ManyToMany(fetch=FetchType.LAZY)
    public Set<String> ips= new HashSet<String>();

    ...

}

但当我尝试启动 webapp 时出现错误,休眠已关闭:

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: my.webapp.Site.ips[java.lang.String]

有什么问题?

【问题讨论】:

    标签: java hibernate jpa orm many-to-many


    【解决方案1】:

    如果您与实体没有关系,则不能使用关系注释(即@ManyToMany)。如果您有基本类型(如本例中的字符串),您应该使用@ElementCollection

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      相关资源
      最近更新 更多