title: How to fix Hibernate Unknown entity exception?
body: <p>I have HibernateSesstion factory class for getting sesion</p>
  <pre><code>public class HibernateSessionFactory {
  
      private static SessionFactory sessionFactory = buildSessionFactory();
  
      protected static SessionFactory buildSessionFactory(){
  
          Configuration configuration = new Configuration();
          ServiceRegistry registry = new StandardServiceRegistryBuilder()
                  .loadProperties(&quot;hibernate.properties&quot;).build();
          try {
              sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
          }catch (Exception e){
              StandardServiceRegistryBuilder.destroy(registry);
              e.printStackTrace();
          }
          return sessionFactory;
      }
  
      public static SessionFactory getSessionFactory(){
          if (sessionFactory.isClosed()){
              buildSessionFactory();
          }
          return sessionFactory;
      }
  </code></pre>
  <p>My entity class</p>
  <pre><code>@Entity()
  @Table(name = &quot;user_commands&quot;)
  public class UserCommands implements Serializable {
  
      @Id
      @Column(name = &quot;chat_id&quot;)
      private Long chatId;
      @Column(name = &quot;last_command&quot;)
      private String lastCommand;
  
      public Long getChatId() {
          return chatId;
      }
  
      public void setChatId(Long chatId) {
          this.chatId = chatId;
      }
  
      public String getLastCommand() {
          return lastCommand;
      }
  
      public void setLastCommand(String lastCommand) {
          this.lastCommand = lastCommand;
      }
  }
  </code></pre>
  <p>And my function from class <code>UserCommandsRepository</code> which select some data</p>
  <pre><code>String sql = &quot;update user_commands set last_command = :lastCommand where chat_id = :chatId&quot;;
  Session session = HibernateSessionFactory.getSessionFactory().openSession();
  session.beginTransaction();
  session.saveOrUpdate(userCommands);
  session.getTransaction().commit();
  session.close();
  </code></pre>
  <p>My hibernate.property file</p>
  <pre><code>hibernate.dialect=org.hibernate.dialect.MySQLDialect
  hibernate.connection.driver_class=com.mysql.jdbc.Driver
  hibernate.connection.url=jdbc:mysql://URL
  hibernate.connection.username=USERNAME
  hibernate.connection.password=PASSWORD
  hibernate.show_sql=true
  hibernate.hbm2ddl=update
  </code></pre>
  <p>When I am trying to run my Main.java class, it's failing with error</p>
  <pre><code>Exception in thread &quot;main&quot; org.hibernate.MappingException: Unknown entity: entity.UserCommands
      at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:704)
      at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1609)
      at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:293)
      at org.hibernate.event.internal.EntityState.getEntityState(EntityState.java:59)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:85)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:75)
      at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
      at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:617)
      at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:610)
      at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:605)
      at repository.UserCommandsRepository.updateLastUserCommand(UserCommandsRepository.java:13)
      at highwayMotorsTelergramBot.Main.main(Main.java:26)
  
  </code></pre>