title: Code example to retrieve table name for an entity in JPA in runtime?
body: <p>I want to list all Database Table names for my JPA Entity model, but I can't get the correct Entity class!</p>
  
  <pre><code>EntityManagerFactory factory;
  Set&lt;EntityType&lt;?&gt;&gt; entities = factory.getMetamodel().getEntities();
  for (EntityType entity: entities) {
      String tableName = entity.getClass().getAnnotation(Table.class).name();
      logger.debug("Entity name  = {}", entity.getName(); //This works
      logger.debug("Entity class = {}", entity.getClass().getName()); //This returns the runtime class of the object, and not the entity class!!
      logger.debug("Entity table = {}", entity.getClass().getAnnotation(Table.class).name()); //Nothing, because it does not find the correct class
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Entity name  = PersonEntity
  Entity class = org.hibernate.jpa.internal.metamodel.EntityTypeImpl
  Entity table = ........ nothing, because this works on the EntityTypeImpl and not on the PersonEnity
  </code></pre>
  
  <p><strong>How do I get the Table name for the Entity Class?</strong></p>