title: Error creating bean entityManagerFactory, NoSuchMethodError: javax/persistence/Table.indexes
body: <p>I have developed a simple application using In Memory HSQLDB and it runs in Websphere Liberty Profile 8.5 over Windows. Now I have published such application in Websphere over z/OS390 Mainframe (Unix) and I am getting the error below. </p>
  
  <p>As far as understand, it should not be affected by the Operation System since it is the same jar (hsqldb-2.3.2.jar), same JDK version (7) and exact same myapp.ear file.</p>
  
  <p>So, my straight question is: what could be the reason for "NoSuchMethodError: javax/persistence/Table.indexes" during entityManagerFactory creation? </p>
  
  <p>What make my life harder is that the exact same ear deployed in my local Websphere doesn't pop up such error. An indirect question could be, is any trick to make in memory HSQLDB run in Unix? Am I reading wrongly the logs and such error is in fact caused by some wrong Spring config? I don't think so because exact same ear runs in another Websphere as said.</p>
  
  <p>I have been struggling for 4 days to find a possible reason but I couldn't. Any suggestion will be highly appreciatted.</p>
  
  <p>Error Logs:</p>
  
  <pre><code>WebSphere non-WLM Dispatch Thread t=009bb7a0¨ ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'
   defined in myapp.config.root.TestConfiguration: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()ÝLjavax/persistence/Index;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java
  </code></pre>
  
  <p>TestConfiguration.java</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  public class TestConfiguration {
      @Bean(initMethod = "init")
      public TestDataInitializer initTestData() {
          return new TestDataInitializer();
      }
  
      @Bean(name = "datasource")
      public DriverManagerDataSource dataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
          dataSource.setUrl("jdbc:hsqldb:mem:mydb");
          dataSource.setUsername("sa");
          dataSource.setPassword("jdbc:hsqldb:mem:mydb");
  
          System.out.println("Untill here was printed without error");
  
          return dataSource;
  
      }
  
      @Bean(name = "entityManagerFactory")
  
      public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) {
  
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          entityManagerFactoryBean.setDataSource(dataSource);
          entityManagerFactoryBean.setPackagesToScan(new String[]{"myapp.model"});
  
          entityManagerFactoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
          entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
  
          Map&lt;String, Object&gt; jpaProperties = new HashMap&lt;String, Object&gt;();
          jpaProperties.put("hibernate.hbm2ddl.auto", "create");
          jpaProperties.put("hibernate.show_sql", "true");
          jpaProperties.put("hibernate.format_sql", "true");
          jpaProperties.put("hibernate.use_sql_comments", "true");
          entityManagerFactoryBean.setJpaPropertyMap(jpaProperties);
          System.out.println("Untill here was printed without error also");
  
          return entityManagerFactoryBean;
      }
  }
  </code></pre>
  
  <p>TestDataInitializer</p>
  
  <pre><code>import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  import javax.persistence.EntityManagerFactory;
  @Component
  public class TestDataInitializer {
  
         @Autowired
         private EntityManagerFactory entityManagerFactory;
  
         @Autowired
         AnotherModelRepository anotherModelRepository;
  
         public void init() throws Exception {
                SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
  
                Session session = sessionFactory.openSession();
                Transaction transaction = session.beginTransaction();
  
  … few session.persit(mymodel)…
  </code></pre>
  
  <p>POM:</p>
  
  <pre><code>&lt;properties&gt;
  
                &lt;java-version&gt;1.7&lt;/java-version&gt;
  
                &lt;org.springframework-version&gt;4.1.3.RELEASE&lt;/org.springframework-version&gt;
  
                &lt;spring-security-version&gt;3.2.5.RELEASE&lt;/spring-security-version&gt;
  
                &lt;hibernate.version&gt;4.3.7.Final&lt;/hibernate.version&gt;
  
                &lt;org.slf4j-version&gt;1.6.1&lt;/org.slf4j-version&gt;
  
                &lt;jackson-version&gt;2.4.4&lt;/jackson-version&gt;
  
                &lt;postgres.driver.version&gt;9.3-1100-jdbc41&lt;/postgres.driver.version&gt;
  
         &lt;/properties&gt;
  
  
  
  
  
         &lt;dependencies&gt;
  
  
  
                &lt;!-- Spring --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.springframework-version}&lt;/version&gt;
  
                       &lt;exclusions&gt;
  
                             &lt;!-- Exclude Commons Logging in favor of SLF4j --&gt;
  
                             &lt;exclusion&gt;
  
                                    &lt;groupId&gt;commons-logging&lt;/groupId&gt;
  
                                    &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
  
                             &lt;/exclusion&gt;
  
                       &lt;/exclusions&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.springframework-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.springframework-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.springframework-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
  
                       &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
  
                       &lt;version&gt;${postgres.driver.version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.springframework-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- Hibernate --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  
                       &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
  
                       &lt;version&gt;${hibernate.version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  
                       &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
  
                       &lt;version&gt;${hibernate.version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- Spring security --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
  
                       &lt;version&gt;${spring-security-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
  
                       &lt;version&gt;${spring-security-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
  
                       &lt;version&gt;${spring-security-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;com.allanditzel&lt;/groupId&gt;
  
                       &lt;artifactId&gt;spring-security-csrf-token-filter&lt;/artifactId&gt;
  
                       &lt;version&gt;1.1&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- Logging --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  
                       &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  
                       &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
  
                       &lt;scope&gt;runtime&lt;/scope&gt;
  
                &lt;/dependency&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  
                       &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
  
                       &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
  
                       &lt;scope&gt;runtime&lt;/scope&gt;
  
                &lt;/dependency&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;log4j&lt;/groupId&gt;
  
                       &lt;artifactId&gt;log4j&lt;/artifactId&gt;
  
                       &lt;version&gt;1.2.16&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- Jackson JSON Processor --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
  
                       &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
  
                       &lt;version&gt;${jackson-version}&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- servlet container provided dependencies --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
  
                       &lt;artifactId&gt;tomcat-servlet-api&lt;/artifactId&gt;
  
                       &lt;version&gt;7.0.30&lt;/version&gt;
  
                       &lt;scope&gt;provided&lt;/scope&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;!-- test dependencies --&gt;
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;com.jayway.jsonpath&lt;/groupId&gt;
  
                       &lt;artifactId&gt;json-path&lt;/artifactId&gt;
  
                       &lt;version&gt;0.8.1&lt;/version&gt;
  
                       &lt;scope&gt;test&lt;/scope&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
  
                       &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
  
                       &lt;version&gt;3.3.2&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;junit&lt;/groupId&gt;
  
                       &lt;artifactId&gt;junit&lt;/artifactId&gt;
  
                       &lt;version&gt;4.12&lt;/version&gt;
  
                       &lt;scope&gt;test&lt;/scope&gt;
  
                &lt;/dependency&gt;
  
  
  
                &lt;dependency&gt;
  
                       &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
  
                       &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
  
                       &lt;version&gt;2.3.2&lt;/version&gt;
  
                &lt;/dependency&gt;
  
  
  
  
  
         &lt;/dependencies&gt;
  
  
  
         &lt;build&gt;
  
                &lt;finalName&gt;my-app&lt;/finalName&gt;
  
  
  
                &lt;plugins&gt;
  
                       &lt;plugin&gt;
  
                             &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  
                             &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  
                             &lt;version&gt;2.3.2&lt;/version&gt;
  
                             &lt;configuration&gt;
  
                                    &lt;source&gt;${java-version}&lt;/source&gt;
  
                                    &lt;target&gt;${java-version}&lt;/target&gt;
  
                             &lt;/configuration&gt;
  
                       &lt;/plugin&gt;
  
  
  
  
  
                       &lt;plugin&gt;
  
                             &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  
                             &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
  
                             &lt;version&gt;2.6&lt;/version&gt;
  
                             &lt;configuration&gt;
  
                                    &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
  
                             &lt;/configuration&gt;
  
                       &lt;/plugin&gt;
  
  
  
  
  
                &lt;/plugins&gt;
  
         &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>**** Added in August 28th 2016 2:45am Brazil, São Paulo timezone
  Thanks to the excellent answers provided, I finaly have my application running in both Windows Websphere 8.5 Liberty Profile as in Mainframe z/OS390 Websphere ND 8.5. I added here my solution for future readers. The basic trick was (1) downgrade Hibernate in order to use JPA2 and use EntityManager.getDelegate() </p>
  
  <pre><code>@Component
  
  public class TestDataInitializer {
  
  
  
         @Autowired
  
         private EntityManagerFactory entityManagerFactory;
  
  
  
         @Autowired
  
         AnotherModelRepository anotherModelRepository;
  
  
  
  //    I TOOK @PersistenceContext OUT
  
  /*     @PersistenceContext
  
         private EntityManager em;*/
  
  
  
         public void init() throws Exception {
  
  //           I REPLACED entityManagerFactory.unwrap AND sessionFactory.openSession OUT
  
                //SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
  
  //Session session = sessionFactory.openSession();
  
  
  
  //            BY createEntityManager AND getDelegate
  
                EntityManager em = entityManagerFactory.createEntityManager();
  
                Session session = (Session) em.getDelegate();
  
                Transaction transaction = session.beginTransaction();
  
  
  
  …
  
  
  
  @Repository
  
  public class MyModelRepository {
  
  /*     @PersistenceContext
  
         private EntityManager em;*/
  
  
  
  
  
         @Autowired
  
         private EntityManagerFactory entityManagerFactory;
  
  
  
         public MyModel findMyModelById(Long MyModel) {
  
                EntityManager em = entityManagerFactory.createEntityManager();
  
                List&lt;MyModel&gt; MyModels = em.createNamedQuery(MyModel.FIND_BY_ID, MyModel.class).setParameter("MyModelId", MyModel).getResultList();
  
  
  
                return MyModels.size() == 1 ? MyModels.get(0) : null;
  
         }
  
  
  
  
  
  
  
         public List&lt;MyModel&gt; findOutByIn(Integer certainId){
  
                //SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
  
                EntityManager em = entityManagerFactory.createEntityManager();
  
                Session session = (Session) em.getDelegate();
  
  
  
                String query = "select c from … c "
  
                       + " inner join … o "
  
                       + " where …;
  
  
  
                //Session session = sessionFactory.openSession();
  
                Transaction transaction = session.beginTransaction();
  
                List&lt;MyModel&gt; l = session.createQuery(query).list();
  
  
  
          return l;
  
  
  
         }
  </code></pre>