休眠问题 - “使用@OneToMany或@ManyToMany定位未映射的类” [英] Hibernate problem - "Use of @OneToMany or @ManyToMany targeting an unmapped class"
问题描述
我有2个实体,Section和ScopeTopic 。 Section有一个List类成员,所以是一对多关系。当我运行我的单元测试时,我得到了这个异常:
使用@OneToMany或@ManyToMany来定位未映射的类:com.xxx。 domain.Section.scopeTopic [com.xxx.domain.ScopeTopic]
我认为错误意味着我的ScopeTopic实体isn' t映射到表?我看不到我做错了。这里是实体类:
@Entity
public class Section {
私人长ID;
私人列表< ScopeTopic> scopeTopics;
$ b $ public Section(){}
@Id
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
@OneToMany
@JoinTable(name =section_scope,joinColumns = {@JoinColumn(name =section_id)},
inverseJoinColumns = {@ JoinColumn(name =scope_topic_id)})
public List< ScopeTopic> getScopeTopic(){
return scopeTopic;
}
public void setScopeTopic(List< ScopeTopic> scopeTopic){
this.scopeTopic = scopeTopic;
@Entity
@Table(name =scope_topic)
public class ScopeTopic {
private Long id;
私人字符串主题;
public ScopeTopic(){}
$ b @Id
public Long getId(){
return id;
}
public void setId(){
this.id = id;
}
public String getTopic(){
return topic;
}
public void setTopic(String topic){
this.topic = topic;
$ / code $ / pre
$ hr
我很确定这是我自己对缺点的理解,所以有些指导是非常好的,谢谢!
你的注释看起来不错。以下是要检查的事项:确保注释 确保你没有在不同的软件包中有多个 javax.persistence.Entity
code>,而不是 org.hibernate.annotations.Entity
。前者使实体可检测。如果你手动列出你的实体(在persistence.xml中,在hibernate.cfg.xml中,或配置你的会话时)。 工厂),然后确保你也列出了 ScopeTopic
实体
ScopeTopic
类,并且导入了错误的。
I'm finding my feet with Hibernate Annotations and I've hit a problem I hope some one can help with.
I have 2 entities, Section and ScopeTopic. Section has a List class member, so a One to Many relationship. When I run my unit test I am getting this exception:
Use of @OneToMany or @ManyToMany targeting an unmapped class: com.xxx.domain.Section.scopeTopic[com.xxx.domain.ScopeTopic]
I would assume that the error implies that my ScopeTopic entity isn't mapped to a table? I can't see with I have done wrong. Here are the Entity classes:
@Entity
public class Section {
private Long id;
private List<ScopeTopic> scopeTopics;
public Section() {}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany
@JoinTable(name = "section_scope", joinColumns = {@JoinColumn(name="section_id")},
inverseJoinColumns = {@JoinColumn(name="scope_topic_id")} )
public List<ScopeTopic> getScopeTopic() {
return scopeTopic;
}
public void setScopeTopic(List<ScopeTopic> scopeTopic) {
this.scopeTopic = scopeTopic;
}
}
@Entity
@Table(name = "scope_topic")
public class ScopeTopic {
private Long id;
private String topic;
public ScopeTopic() {}
@Id
public Long getId() {
return id;
}
public void setId() {
this.id = id;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
}
I'm pretty sure it's my own lack of understanding that's at fault so some guidance would be great, thanks!
Your annotations look fine. Here are the things to check:
make sure the annotation is
javax.persistence.Entity
, and notorg.hibernate.annotations.Entity
. The former makes the entity detectable. The latter is just an addition.if you are manually listing your entities (in persistence.xml, in hibernate.cfg.xml, or when configuring your session factory), then make sure you have also listed the
ScopeTopic
entitymake sure you don't have multiple
ScopeTopic
classes in different packages, and you've imported the wrong one.
这篇关于休眠问题 - “使用@OneToMany或@ManyToMany定位未映射的类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!