Hibernate @ManyToOne references an unknown entity

前端 未结 12 1495
名媛妹妹
名媛妹妹 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 18:10

    The unknown entity error is not a hibernate annotation problem, but rather that the entity is NOT being recognized. You should check your persistence settings, whether you are using pure JPA, Hibernate or Spring.

    By default, Hibernate is capable of finding the JPA entity classes based on the presence of the @Entity annotation, so you don't need to declare the entity classes.

    With Spring you would have an @Bean similar to the following to make sure you don't have unknown entities in your package.

    @Bean
    open fun entityManagerFactory() : 
    LocalContainerEntityManagerFactoryBean {
        val em = LocalContainerEntityManagerFactoryBean()
        em.setPackagesToScan("com.package.domain.entity")
    
        //...
    }
    

    GL

    Source

提交回复
热议问题