我的 web 应用程序中有一些名为 Site 的域对象。 站点将包含 IP 地址列表,即
@Entity
class Site {
...
@ManyToMany(fetch=FetchType.LAZY)
public Set<String> ips= new HashSet<String>();
...
}
但是当我尝试启动 webapp 并出现错误时,hibernate 已关闭:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: my.webapp.Site.ips[java.lang.String]
有什么问题吗?
最佳答案
如果您与实体没有关系,则无法使用关系注释(即@ManyToMany
)。如果您有基本类型(如本例中 - String),您应该使用 @ElementCollection
关于java - 创建实体和非实体对象之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8019850/