title: Hibernate An assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
body: <p>I just changed from hibernate 4.X) to hibernate 5.0, I changed my configuration file accordingly but I'm getting an weird error. </p>
  
  <blockquote>
    <p>An assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table x_database.User not found</p>
  </blockquote>
  
  <p>I hope that you can help. </p>
  
  <p>Below you can see my session file and my XML config file. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration SYSTEM
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.dialect"&gt;
              org.hibernate.dialect.MySQLDialect
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
  
          &lt;!-- Connects to the localhost database. This is for development purposes only. !--&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/x_database&lt;/property&gt;
          &lt;!-- Should the system flush the database before running or only update the database? !--&gt;
          &lt;property name="hbm2ddl.auto"&gt;
              create
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.username"&gt;
              root
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.password"&gt;
              root
          &lt;/property&gt;
  
          &lt;mapping class="org.hva.folivora.model.user.UserEntity"&gt;&lt;/mapping&gt;
          &lt;mapping class="org.hva.folivora.model.user.ParentEntity"&gt;&lt;/mapping&gt;
          &lt;mapping class="org.hva.folivora.model.user.StudentEntity"&gt;&lt;/mapping&gt;
          &lt;mapping class="org.hva.folivora.model.questionanswer.QuestionEntity"&gt;&lt;/mapping&gt;
          &lt;mapping class="org.hva.folivora.model.global.GroupEntity"&gt;&lt;/mapping&gt;
          &lt;mapping class="org.hva.folivora.model.global.ThemeEntity"&gt;&lt;/mapping&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Below my session factory.</p>
  
  <pre><code>    public class Database {
      private static final SessionFactory sessionFactory = buildSessionFactory();
  
      private static SessionFactory buildSessionFactory() {
          try {
              // Create the SessionFactory from hibernate.cfg.xml
              StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
              Metadata metadata = new MetadataSources(standardRegistry).getMetadataBuilder().build();
              return metadata.getSessionFactoryBuilder().build();
          } catch (Throwable ex) {
              // Make sure you log the exception, as it might be swallowed
              System.err.println("Initial SessionFactory creation failed." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public static Session getSession() {
  
          return getSessionFactory().openSession();
      }
  
      public static void main(final String[] args) throws Exception {
          final org.hibernate.Session session = getSession();
          try {
              System.out.println("querying all the managed entities...");
              final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
              for (Object key : metadataMap.keySet()) {
                  final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
                  final String entityName = classMetadata.getEntityName();
                  final Query query = session.createQuery("from " + entityName);
                  System.out.println("executing: " + query.getQueryString());
                  for (Object o : query.list()) {
                      System.out.println("  " + o);
                  }
              }
          } finally {
              session.close();
          }
  
      }
  }
  </code></pre>
  
  <p>Full stacktrace below. </p>
  
  <pre><code>                01-May-2016 18:18:08.136 SEVERE [http-nio-8079-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [IJBurg API/BACKEND] in context with path [] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.ExceptionInInitializerError] with root cause
   org.hibernate.AssertionFailure: Table pad_ijburg.User not found
      at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5139)
      at org.hibernate.persister.entity.JoinedSubclassEntityPersister.&lt;init&gt;(JoinedSubclassEntityPersister.java:433)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:344)
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
      at org.hva.folivora.Database.buildSessionFactory(Database.java:26)
      at org.hva.folivora.Database.&lt;clinit&gt;(Database.java:19)
      at org.hva.folivora.MyResource.getIt(MyResource.java:39)
      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:497)
      at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
      at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:317)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:298)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
      at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1096)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>My sessionfactory</p>
  
  <pre><code>   package org.hva.folivora;
  
  import org.hibernate.HibernateException;
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.Metadata;
  import org.hibernate.boot.MetadataSources;
  import org.hibernate.boot.registry.StandardServiceRegistry;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.metadata.ClassMetadata;
  
  import java.util.Map;
  
  public class Database {
      private static final SessionFactory sessionFactory = buildSessionFactory();
  
      private static SessionFactory buildSessionFactory() {
          try {
              // Create the SessionFactory from hibernate.cfg.xml
              StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
              Metadata metadata = new MetadataSources(standardRegistry).getMetadataBuilder().build();
              return metadata.getSessionFactoryBuilder().build();
          } catch (Throwable ex) {
              // Make sure you log the exception, as it might be swallowed
              System.err.println("Initial SessionFactory creation failed." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public static Session getSession() {
  
          return getSessionFactory().openSession();
      }
  
      public static void main(final String[] args) throws Exception {
          final org.hibernate.Session session = getSession();
          try {
              System.out.println("querying all the managed entities...");
              final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
              for (Object key : metadataMap.keySet()) {
                  final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
                  final String entityName = classMetadata.getEntityName();
                  final Query query = session.createQuery("from " + entityName);
                  System.out.println("executing: " + query.getQueryString());
                  for (Object o : query.list()) {
                      System.out.println("  " + o);
                  }
              }
          } finally {
              session.close();
          }
  
      }
  }
  
  package org.hva.folivora.model.user;
  
  import javax.jws.soap.SOAPBinding;
  import javax.persistence.*;
  
  @Entity
  @Table(name = "User", schema = "pad_ijburg")
  @Inheritance(strategy = InheritanceType.JOINED)
  public class UserEntity {
      private int idUser;
      private String email;
      private String firstName;
      private String lastName;
      private String password;
      private Boolean admin = false;
      private Boolean teacher = false;
  
      public UserEntity(){
  
      }
  
      public UserEntity(String email, String firstName, String lastName, String password, Boolean admin, Boolean teacher){
          this.email = email;
          this.firstName = firstName;
          this.lastName = lastName;
          this.password = password;
          this.admin = admin;
          this.teacher = teacher;
      }
  
      @Basic
      @Column(name = "teacher")
      public Boolean getTeacher() {
          return teacher;
      }
  
      public void setTeacher(Boolean teacher) {
          this.teacher = teacher;
      }
  
      @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "idUser", nullable = false, updatable = false, unique = true)
      public int getIdUser() {
          return idUser;
      }
  
      public void setIdUser(int idUser) {
          this.idUser = idUser;
      }
  
      @Basic
      @Column(name = "email", unique = true, nullable = false)
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      @Basic
      @Column(name = "firstName")
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      @Basic
      @Column(name = "lastName")
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      @Basic
      @Column(name = "password")
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      @Basic
      @Column(name = "admin")
      public Boolean getAdmin() {
          return admin;
      }
  
      public void setAdmin(Boolean admin) {
          this.admin = admin;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
  
          UserEntity that = (UserEntity) o;
  
          if (idUser != that.idUser) return false;
          if (email != null ? !email.equals(that.email) : that.email != null) return false;
          if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) return false;
          if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) return false;
          if (password != null ? !password.equals(that.password) : that.password != null) return false;
          if (admin != null ? !admin.equals(that.admin) : that.admin != null) return false;
  
          return true;
      }
  
      @Override
      public int hashCode() {
          int result = idUser;
          result = 31 * result + (email != null ? email.hashCode() : 0);
          result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
          result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
          result = 31 * result + (password != null ? password.hashCode() : 0);
          result = 31 * result + (admin != null ? admin.hashCode() : 0);
          return result;
      }
  }
  </code></pre>