2011-02-10 3 views
76

최대 절전 모드 특수 효과로 발을 찾는데 도움이 될만한 문제가 발생했습니다.최대 절전 모드 문제 - "매핑되지 않은 클래스를 대상으로 @OneToMany 또는 @ManyToMany 사용"

두 개의 엔티티 인 Section과 ScopeTopic이 있습니다. 섹션에는 List 클래스 멤버가 있으므로 일대 다 관계가됩니다. @OneToMany 또는 @ManyToMany가 매핑되지 않은 클래스를 대상으로의

사용 : : 내 단위 테스트를 실행할 때 나는이 예외를 얻고있다 com.xxx.domain.Section.scopeTopic [com.xxx.domain.ScopeTopic]

나는이 오류가 내 ScopeTopic 엔티티가 테이블에 매핑되어 있지 않다는 것을 의미한다고 생각합니까? 내가 잘못했을 때 나는 볼 수 없다. 다음은 엔티티 클래스는 다음과 같습니다


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

나는 그렇게 몇 가지 지침이 좋은 것 잘못 이해 내 자신의 부족, 덕분 확신합니다!

답변

178

주석이 잘 보입니다. 여기에 일을 확인할 수 있습니다

  • 는 주석이 javax.persistence.Entity, 그리고 org.hibernate.annotations.Entity 있는지 확인합니다. 전자는 엔티티를 탐지 가능하게 만듭니다. 후자는 단지 추가 일뿐입니다. (세션 팩토리를 구성 할 때 hibernate.cfg.xml 내의 persistence.xml에서, 또는)

  • 수동으로 개체를 나열하는 경우, 다음 있는지 확인 당신은 또한

  • 지 확인하세요 ScopeTopic 개체를 나열했습니다 서로 다른 패키지에 여러 개의 ScopeTopic 클래스가 없으며 잘못된 클래스를 가져 왔습니다.

+13

아 삼았 hibernate.cfg.xmlEntity 클래스를 추가 감사가 필요하지 않은! Point 2가 핵심이었고, SessionFactory, n00b 오류를 만들 때 annotatedClasses 속성 목록에 ScopeTopic을 넣는 것을 잊었습니다! – C0deAttack

+4

포인트 1이 나를위한 열쇠였습니다 : D thanks –

+3

그냥이 코멘트를 치는 사람들에게. org.hibernate.annotations.Entity는 Hibernate 4에서 더 이상 사용되지 않는다. Point 1은 더 이상 적용되지 않는다. – gspatel

17

엔티티가 최대 절전 모드 구성 파일에 나열되지 않을 수 있습니다.

10

광산, Hibernate

@Entity // this was commented 
@Table(name = "some_table") 
public class ChildEntity { 
    @JoinColumn(name = "parent", referencedColumnName = "id") 
    @ManyToOne 
    private ParentEntity parentEntity; 
} 
4

대부분 여러 측면 엔티티에 @Entity을 가지고

</hibernate-configuration> 
    </session-factory> 

    .... 
    <mapping class="xxx.xxx.yourEntityName"/> 
</session-factory> 
</hibernate-configuration>