I am receiving the following Hibernate Exception:
@OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team
The simplified
Another solution: Check to ensure that the referenced class is included your hibernate.cfg.xml
file.
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 {
}
I figured out the problem: I was not adding class Team to the Hibernate AnnotationConfiguration
object. Thus, Hibernate was not recognizing the class.
Add the class in hibernate.cfg
in proper order. First map the file that is going to be referred by another class
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)
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