Hibernate @ManyToOne references an unknown entity

前端 未结 12 1311
名媛妹妹
名媛妹妹 2021-01-03 17:54

I am receiving the following Hibernate Exception:

@OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team

The simplified

相关标签:
12条回答
  • 2021-01-03 17:58

    Another solution: Check to ensure that the referenced class is included your hibernate.cfg.xml file.

    0 讨论(0)
  • 2021-01-03 17:58

    If you are using Spring Boot in combination with hibernate, then actually you may just need to add the package to your @EntityScan base package array.

    @SpringBootApplication(scanBasePackages = {"com.domain.foo.bar.*"})
    @EnableJpaRepositories(basePackages ={"com.domain.foo.bar.*"})
    @EntityScan(basePackages ={"com.domain.foo.bar.*", "com.domain.another.*"})
    public class SpringBootApplication extends SpringBootServletInitializer {
    }
    
    0 讨论(0)
  • 2021-01-03 18:00

    I figured out the problem: I was not adding class Team to the Hibernate AnnotationConfiguration object. Thus, Hibernate was not recognizing the class.

    0 讨论(0)
  • 2021-01-03 18:00

    Add the class in hibernate.cfg in proper order. First map the file that is going to be referred by another class

    0 讨论(0)
  • 2021-01-03 18:01

    If you do not use the hibernate.cfg.xml you can add targetEntity parameter in @ManyToOne/@OneToMany annotation with class describing your entity.

    For instance:

    @ManyToOne(targetEntity = some.package.MyEntity.class)
    
    0 讨论(0)
  • 2021-01-03 18:03

    Try to add the Qualified Name (ClassNAME), just like this:

    <hibernate-configuration>
        <session-factory name="java:/hibernate/SessionFactory">
                      <mapping class="co.com.paq.ClassNAME" />
            </session-factory>
    </hibernate-configuration>
    

    In the File:

    META-INF/hibernate.cfg.xml
    
    0 讨论(0)
提交回复
热议问题