title: how to display mysql view in spring boot?
body: <p>I have a Spring Boot CRUD app that is working, as long as I use regular MySQL tables.  But I need to display data from multiple tables so I created a MySQL view.  But getting the following error now:</p>
  
  <blockquote>
    <p>Error creating bean with name 'entityManagerFactory' defined in class
    path resource
    [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
    Invocation of init method failed; nested exception is
    org.hibernate.AnnotationException: No identifier specified for entity:
    net.tekknow.medaverter.domain.AppointmentView</p>
  </blockquote>
  
  <p>I was following this example: 
  <a href="https://www.javabullets.com/calling-database-views-from-spring-data-jpa/" rel="nofollow noreferrer">https://www.javabullets.com/calling-database-views-from-spring-data-jpa/</a></p>
  
  <p>Here is the domain object:</p>
  
  <pre><code>package net.tekknow.medaverter.domain;
  
  import java.io.Serializable;
  import java.sql.Timestamp;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.validation.constraints.Size;
  
  @Entity
  @Table(name = "vw_appointments")
  public class AppointmentView implements Serializable {
      @Size(max = 32)
      @Column(name="Date")
      public String date;
  
      @Column(name="Physician")
      public String physician;
  
      @Column(name="LabCollected")
      public Timestamp labCollected;
  
      @Column(name="Note")
      public String note;
  
      public String getDate_time() {
          return date;
      }
      public String getPhysician() {
          return physician;
      }
      public Timestamp getDatetime_collected() {
          return labCollected;
      }
      public String getNote() {
          return note;
      }
  }
  </code></pre>
  
  <p>Here is a mysql query of the view, just to show you it works:</p>
  
  <blockquote>
    <p>mysql> select * from vw_appointments;
    +------------+-------------+---------------------+-------------------+ | Date       | Physician   | LabCollected        | Note              |
    +------------+-------------+---------------------+-------------------+ | 10/29/2010 | CAMPBELL, J | 2010-10-29 11:09:00 | no note available |
    +------------+-------------+---------------------+-------------------+ 1 row in set (0.02 sec)</p>
  </blockquote>
  
  <p>Here is the service code:</p>
  
  <pre><code>@Service
  @Transactional
  public class AppointmentViewService {
  
      @Autowired
      AppointmentViewRepository repo;
  
      public List&lt;AppointmentView&gt; listAll() {
          return repo.findAll();
      }      
  }
  </code></pre>
  
  <p>Here is the repository code:</p>
  
  <pre><code>public interface AppointmentViewRepository extends JpaRepository&lt;AppointmentView,Integer&gt; {}
  </code></pre>
  
  <p>Does Hibernate not handle views?  Suggestions?</p>