title: Why does my Entity does not work with SpringBoot although it works without
body: <p><em>(Please note : while investigating on <a href="https://stackoverflow.com/questions/52799706/springboot-not-an-entity?noredirect=1#comment92527948_52799706">this issue</a> I better spotted the source of problem that I introduce here)</em></p>
  
  <p>I am very new to Hibernate and SpringBoot. My project deals with a search engine which indexing (javafx client) and searching (web client) parts are separated. The web client uses SpringBoot and during the process of the user's request, I need to retrieve information on the Solr Index to search against. These information are stored in a Hibernate / H2 local database where I use the following Entity class :</p>
  
  <pre><code>@Entity
  @Table(name = "IndexSetups")
  @Access(AccessType.PROPERTY)
  public class IndexSetup {
   private final SimpleIntegerProperty id = new SimpleIntegerProperty();
  
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO) // For H2 AUTO is required to auto increment the id
   public int getId() {
    return id.get();
  }
  
   //... other properties, getters and setters
  
  }
  </code></pre>
  
  <p>A LocalDatabase class features a method to list all IndexSetups from the DB (there are also other methods but focusing on this one is enough to understand the issue). I need to call it in a controller but I get a <a href="https://stackoverflow.com/questions/52799706/springboot-not-an-entity?noredirect=1#comment92527948_52799706">"Not an entity : class IndexSetup"</a>.</p>
  
  <p>However the only way to use my Entity is to prevent the launching of SpringBoot (ie commenting the line starting with SpingApplication.run(...)) :</p>
  
  <pre><code>@SpringBootApplication
  public class ServerApplication {
  
  public static void main(String[] args) {
  //      SpringApplication.run(ServerApplication.class, args); 
  
  ArrayList&lt;IndexSetup&gt; availableSearchIndex = 
  LocalDatabase.getInstance(false) // no GUI
              .getAllIndexSetups();
  
  // The list is displayed as long as SpringApplication.run() call is commented. Otherwise "Not an entity"
  System.err.println("The Index setups are " + availableSearchIndex); 
    }
  }
  </code></pre>
  
  <p>Of course this is not a solution since I do need to process the user's request via Spring Boot :-D!</p>
  
  <p>Finally the hibernate.cfg.xml file reads :</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;      
      &lt;!-- Database connection settings --&gt;
      &lt;property name="connection.driver_class"&gt;org.h2.Driver&lt;/property&gt;
      &lt;!--The db file resides wihtin the parent project (so one level above the calling project see ../)--&gt;
      &lt;!--We use the auto server mode to be able to open the database from server and from indexer simultaneously
      see http://www.h2database.com/html/features.html#auto_mixed_mode --&gt;
      &lt;property name="connection.url"&gt;jdbc:h2:file:../MyAppDB;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=TRUE&lt;/property&gt;
      &lt;property name="connection.username"&gt;test&lt;/property&gt;
      &lt;property name="connection.password"/&gt;
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;!-- SQL dialect --&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/property&gt;
      &lt;!-- Disable the second-level cache --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;false&lt;/property&gt;
      &lt;!-- Updates the existing database schema on startup --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;!-- The mapping information of entities --&gt;
      &lt;mapping class="my.package.Entities.IndexSetup"/&gt;
   &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>The stack trace is :</p>
  
  <pre><code>Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
  
  Caused by: java.lang.IllegalArgumentException: Not an entity: class my.package.Entities.IndexSetup
  at org.hibernate.metamodel.internal.MetamodelImpl.entity(MetamodelImpl.java:457)
  at org.hibernate.query.criteria.internal.QueryStructure.from(QueryStructure.java:126)
  at org.hibernate.query.criteria.internal.CriteriaQueryImpl.from(CriteriaQueryImpl.java:153)
  at my.package.LocalDatabase.getAllIndexSetups(LocalDatabase.java:99)
  at my.package.ServerApplication.main(ServerApplication.java:15)
  </code></pre>
  
  <p>And I've just noticed those two lines printed by Spring Boot at startup :</p>
  
  <pre><code>2018-10-15 11:47:46.208  INFO 27730 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found // Maybe this one is not just "INFO"
  2018-10-15 11:47:46.591  WARN 27730 --- [  restartedMain] org.hibernate.orm.connections.pooling    : HHH10001002: Using Hibernate built-in connection pool (not for production use!)
  2018-10-15 11:47:46.594  INFO 27730 --- [  restartedMain] org.hibernate.orm.connections.pooling    : HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:file:../MyAppDB;DB_CLOSE_ON_EXIT=TRUE;FILE_LOCK=NO] // Just to show that my bibernate.cfg.xml is found
  </code></pre>
  
  <p>It looks unlikely to be a dependency problem as it only stops working when Spring application is run. </p>
  
  <p>So my question is : what should I do to make my Entity work within SpringBoot ?</p>
  
  <p>Any help much appreciated!</p>