title: Accessing a relational database using spring jpa/vaadin
body: <p>I have a database setup in mysql with two tables:</p>
  <p><strong>stock_info</strong></p>
  <p><img src="https://i.stack.imgur.com/a2Svp.png" alt="stock_info table" /></p>
  <p><strong>stock_price_data:</strong></p>
  <p><img src="https://i.stack.imgur.com/6FWgS.png" alt="stock_price_data table" /></p>
  <p>The primary key for the first table is set as 'Ticker' and the foreign key of the second one refers to 'Ticker' from the first table also, representing a one to many relationship.</p>
  <p>I am trying to access this data within a vaadin web app using spring data. I have attempted to pull all the data from the tables using services, repositories and two entities which extend from an <code>AbstractEntity</code>. I am receiving the following errors when I run however:</p>
  <pre><code>
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stockPriceRepository' defined in com.stockmachine.v2.backend.repository.StockPriceRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is ...
  </code></pre>
  <p>It is clearly something to do with my referencing/ mapping of the one-to many relationship, but after some googling I still cannot find a solution.</p>
  <p>These are my entity classes:</p>
  <pre><code>package com.stockmachine.v2.backend.entity;
  
  import javax.persistence.*;
  import javax.validation.constraints.Email;
  import javax.validation.constraints.NotEmpty;
  import javax.validation.constraints.NotNull;
  
  @Entity
  @Table (name=&quot;stock_info&quot;)
  public class Stock extends AbstractEntity implements Cloneable {
      //@Id
      //private String Ticker;
      @ManyToOne
      @JoinColumn(name = &quot;Ticker&quot;)
      //private StockPrice stockPrice;
      
      private String Region;
  
      private String Sector;
      
      private String Industry;
      
      private String Type;
      
      /*public String getTicker() {
          return Ticker;
      }
      public void setTicker(String ticker) {
          Ticker = ticker;
      }*/
      
      public String getRegion() {
          return Region;
      }
      public void setRegion(String region) {
          Region = region;
      }
      public String getSector() {
          return Sector;
      }
      public void setSector(String sector) {
          Sector = sector;
      }
      public String getIndustry() {
          return Industry;
      }
      public void setIndustry(String industry) {
          Industry = industry;
      }
      public String getType() {
          return Type;
      }
      public void setType(String type) {
          Type = type;
      }
      
      
  
  }
  </code></pre>
  <pre><code>package com.stockmachine.v2.backend.entity;
  import javax.persistence.*;
  import java.util.LinkedList;
  import java.util.List;
  @Entity
  @Table(name=&quot;stock_price_data&quot;)
  public class StockPrice extends AbstractEntity  {
      @OneToMany(targetEntity=Stock.class, mappedBy=&quot;stock&quot;, fetch=FetchType.LAZY, cascade=CascadeType.ALL)
      @JoinColumn(name=&quot;Ticker&quot;)
      
      
      private double Price;
  
      private double open_price;
  
      private double close_price;
  
      private double volume;
      
      private double relative_strength;
      
      private double ma30;
      
      private double ma7;
      
      private double ma365;
      
      private String date_time;
          
          
  
      public double getPrice() {
          return Price;
      }
  
      public void setPrice(double price) {
          Price = price;
      }
  
      public double getOpen_price() {
          return open_price;
      }
  
      public void setOpen_price(double open_price) {
          this.open_price = open_price;
      }
  
      public double getClose_price() {
          return close_price;
      }
  
      public void setClose_price(double close_price) {
          this.close_price = close_price;
      }
  
      public double getVolume() {
          return volume;
      }
  
      public void setVolume(double volume) {
          this.volume = volume;
      }
  
      public double getRelative_strength() {
          return relative_strength;
      }
  
      public void setRelative_strength(double relative_strength) {
          this.relative_strength = relative_strength;
      }
  
      public double getMa30() {
          return ma30;
      }
  
      public void setMa30(double ma30) {
          this.ma30 = ma30;
      }
  
      public double getMa7() {
          return ma7;
      }
  
      public void setMa7(double ma7) {
          this.ma7 = ma7;
      }
  
      public double getMa365() {
          return ma365;
      }
  
      public void setMa365(double ma365) {
          this.ma365 = ma365;
      }
  
      public String getDate_time() {
          return date_time;
      }
  
      public void setDate_time(String date_time) {
          this.date_time = date_time;
      }
  
          
  
  
          
          
  }
  </code></pre>
  <pre><code>package com.stockmachine.v2.backend.entity;
  
  import java.io.Serializable;
  
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.MappedSuperclass;
  
  @MappedSuperclass
  public abstract class AbstractEntity implements Serializable {
      
    @Id
    private String Ticker;
  
  public String getTicker() {
     return Ticker;
    }
  
    public boolean isPersisted() {
      return Ticker != null;
    }
  
    @Override
    public int hashCode() {
      if (getTicker() != null) {
        return getTicker().hashCode();
      }
      return super.hashCode();
    }
  
    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (obj == null) {
        return false;
     }
      if (getClass() != obj.getClass()) {
        return false;
      }
      AbstractEntity other = (AbstractEntity) obj;
   if (getTicker() == null || other.getTicker() == null) {
        return false;
      }
      return getTicker().equals(other.getTicker());
    }
    
  }
  </code></pre>
  <h1>Edit </h1>
  <hr>
  Thanks to the suggestions I have decided to remove the Abstract entity altogether and have changed the entity classes as follows:
  <pre><code>public class Stock implements Cloneable {
      @OneToMany(mappedBy=&quot;stock&quot;, fetch=FetchType.LAZY, 
  cascade=CascadeType.ALL)
      @Id
      private List&lt;StockPrice&gt; Ticker;
      private String Price;
      ...
       
      public List&lt;StockPrice&gt; getTicker() {
          return Ticker;
      }
      public void setTicker(List&lt;StockPrice&gt; ticker) {
          Ticker = ticker;
      }
  </code></pre>
  <p>yet I am still getting the same (or similar) error:</p>
  <pre><code>
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stockRepository' defined in com.stockmachine.v2.backend.repository.StockRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.stockmachine.v2.backend.entity.StockPrice
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1697) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1442) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:624) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.data.repository.config.DeferredRepositoryInitializationListener.onApplicationEvent(DeferredRepositoryInitializationListener.java:51) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.data.repository.config.DeferredRepositoryInitializationListener.onApplicationEvent(DeferredRepositoryInitializationListener.java:36) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
      at com.stockmachine.v2.Application.main(Application.java:14) ~[classes/:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
      at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.3.2.RELEASE.jar:2.3.2.RELEASE]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.stockmachine.v2.backend.entity.StockPrice
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      ... 33 common frames omitted
  Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.stockmachine.v2.backend.entity.StockPrice
      at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:254) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:230) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:273) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.8.RELEASE.jar:5.2.8.RELEASE]
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
      at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
  </code></pre>
  <p>and</p>
  <pre><code>public class StockPrice  {
      @ManyToOne
      @JoinColumn(name = &quot;Ticker&quot;)
      private StockPrice stockPrice;
  
      private List&lt;Double&gt; Price;
      ...
  </code></pre>