title: java.sql.SQLException Invalid object name
body: <p>I get the error below when I try to read from the database using <code>createQuery</code> but I can read from the database if I use <code>createNativeQuery</code> on my <code>entityManager</code>. So I guess my <code>entityManager</code> works but something is wrong with my Hibernate configuration?</p>
  
  <p>application.properties:</p>
  
  <pre><code>security.user.password=&lt;password&gt;
  logging.level.org.springframework.security=DEBUG
  spring.datasource.url=jdbc:jtds:sqlserver://localhost:60830;databaseName=&lt;db&gt;
  spring.datasource.username=&lt;user&gt;
  spring.datasource.password=&lt;password&gt;
  spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
  spring.jpa.show-sql=true
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.properties.hibernate.id.new_generator_mappings=false
  spring.jpa.properties.hibernate.format_sql=true
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
  spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>package demo.dao;
  
  import demo.entities.StampCard;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import javax.persistence.Query;
  
  @Transactional
  @Repository
  public class StampCardDAO implements IStampCardDAO {
  
      @PersistenceContext
      private EntityManager entityManager;
  
      @Override
      public StampCard getStampCard(int id) {
          //These rows works fine
          //Query query = entityManager.createNativeQuery("select userId from StampCard where StampCardID = '1'");
          //String userId = (String) query.getSingleResult();
          Query query = entityManager.createQuery("SELECT s FROM StampCard s WHERE s.stampCardID = '1'");
          StampCard stampCard = (StampCard) query.getSingleResult();
          return stampCard;
      }
  }
  </code></pre>
  
  <p>Interface for DAO:</p>
  
  <pre><code>package demo.dao;
  
  import demo.entities.StampCard;
  
  public interface IStampCardDAO {
  
      StampCard getStampCard(int id);
  }
  </code></pre>
  
  <p>Entity:</p>
  
  <pre><code>package demo.entities;
  
  import lombok.Getter;
  import lombok.Setter;
  import org.apache.commons.lang3.builder.EqualsBuilder;
  import org.apache.commons.lang3.builder.HashCodeBuilder;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import java.io.Serializable;
  
  @Entity
  public class StampCard implements Serializable {
  
      private static final long serialVersionUID = 6602888822739626415L;
  
      private int stampCardID;
      @Getter @Setter private String createdDate;
      @Getter @Setter private String userID;
      @Getter @Setter private int numberOfStamps;
  
      @Id
      public int getStampCardID() {
          return stampCardID;
      }
  
      public void setStampCardID(int stampCardID) {
          this.stampCardID = stampCardID;
      }
  
      @Override 
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (obj == this) {
              return true;
          }
          if (obj.getClass() != getClass()) {
              return false;
          }
          StampCard rhs = (StampCard) obj;
          return new EqualsBuilder().append(this.stampCardID, rhs.stampCardID).append(this.createdDate, rhs.createdDate).append(this.userID, rhs.userID)
                  .append(this.numberOfStamps, rhs.numberOfStamps).isEquals();
      }
  
      @Override 
      public int hashCode() {
          return new HashCodeBuilder().append(stampCardID).append(createdDate).append(userID).append(numberOfStamps).toHashCode();
      }
  }
  </code></pre>
  
  <p>Database table:</p>
  
  <pre><code>CREATE TABLE [dbo].[StampCard](
      [StampCardID] [int] NOT NULL,
      [CreatedDate] [varchar](8) NOT NULL,
      [UserID] [varchar](255) NOT NULL,
      [NumberOfStamps] [int] NOT NULL,
   CONSTRAINT [PK_CardID] PRIMARY KEY CLUSTERED 
  (
      [StampCardID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>Database table content:</p>
  
  <pre><code>StampCardID CreatedDate UserID  NumberOfStamps
  1           20171208    USer    1
  </code></pre>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>2017-12-10 18:04:09.837  WARN 37080 --- [  restartedMain]
    o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 208, SQLState:
    S0002 2017-12-10 18:04:09.840 ERROR 37080 --- [  restartedMain]
    o.h.engine.jdbc.spi.SqlExceptionHelper   : Invalid object name
    'stamp_card'.</p>
    
    <p>Caused by: java.sql.SQLException: Invalid object name 'stamp_card'.</p>
  </blockquote>
  
  <p>I am thankful for all the help I can get.</p>