title: Error in relationship mapping on spring boot hibernate
body: <p>I am using Spring Boot 1.5.9.RELEASE and I am facing a compile time error in EntityManagerFactory. I can do CRUD operations in tables not having any foreign keys but in tables having foreign keys, the pproject doesn't even compile complaining about EntityManagerFactory. I am using Intellij IDEA 2017.3. Below is my Model Class:</p>
  
  <pre><code>package com.example.demo.Model;
  
  import javax.persistence.*;
  
  @Entity
  @Table(name = "student")
  public class Student {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "sid")
      private int id;
  
      @Column(name = "sname")
      private String name;
  
      @Column(name = "sroll")
      private int roll;
  
      @ManyToOne
      @JoinColumn(name = "cid", table = "college")
      private College college;
  
      public int getId() {
          return id;
      }
  
      public College getCollege() {
          return college;
      }
  
      public void setCollege(College college) {
          this.college = college;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getRoll() {
          return roll;
      }
  
      public void setRoll(int roll) {
          this.roll = roll;
      }
  }
  
      package com.example.demo.Model;
  
      import javax.persistence.*;
      import java.util.List;
  
      @Entity
      @Table(name = "college")
      public class College {
  
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Id
      @Column(name = "cid")
      private int id;
  
      @Column(name = "cname")
      private String name;
  
      @OneToMany(targetEntity = Student.class, mappedBy = "college",
              cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private List&lt;Student&gt; studentList;
  
      public List&lt;Student&gt; getStudentList() {
          return studentList;
      }
  
      public void setStudentList(List&lt;Student&gt; studentList) {
          this.studentList = studentList;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>My DAO classes are as follows:</p>
  
  <pre><code>package com.example.demo.DAO;
  
  import com.example.demo.Model.College;
  import org.springframework.stereotype.Repository;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.PersistenceUnit;
  import javax.transaction.Transactional;
  
  @Transactional
  @Repository
  public class CollegeDAO {
  
      @PersistenceUnit
      EntityManagerFactory emf;
  
      public boolean add(College college) {
  
          EntityManager em = emf.createEntityManager();
          em.getTransaction().begin();
          em.persist(college);
          em.getTransaction().commit();
  
          return true;
      }
  }
  
  package com.example.demo.DAO;
  
  
  import com.example.demo.Model.Student;
  import org.apache.tomcat.jni.Local;
  import org.springframework.stereotype.Repository;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.PersistenceUnit;
  import javax.transaction.Transactional;
  import java.util.List;
  
  @Transactional
  @Repository
  public class StudentDAO {
  
      @PersistenceUnit
      private EntityManagerFactory emf;
  
      public boolean add(Student student) {
  
          EntityManager em = emf.createEntityManager();
          em.getTransaction().begin();
          em.persist(student);
          em.getTransaction().commit();
  
          return true;
      }
  }
  </code></pre>
  
  <p>The error stack is as follows:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Cannot find the expected secondary table: no college available for com.example.demo.Model.Student
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.10.RELEASE.jar:1.5.10.RELEASE]
  Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no college available for com.example.demo.Model.Student
      at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:452) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:423) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2854) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1763) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:911) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:738) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:382) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      ... 21 common frames omitted
  </code></pre>