title: How to find compatible version pair of Hibernate + Spring-JPA? (Could not open JPA EntityManager for transaction)
body: <p>SSCCE is here: <a href="https://github.com/dims12/TrySpringJpaPlusHibernate" rel="noreferrer">https://github.com/dims12/TrySpringJpaPlusHibernate</a></p>
  
  <p>I am trying to run Spring JPA without persistence.xml and have the following config:</p>
  
  <pre><code>@Configuration
  @ComponentScan
  @ImportResource("classpath:data_source.xml")
  @EnableJpaRepositories("org.inthemoon.train.chinese.repositories")
  public class BaseConfig {
     @Autowired
     private DataSource dataSource;
  
     @Bean
     public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean ans =
           new LocalContainerEntityManagerFactoryBean();
        ans.setDataSource(dataSource);
        ans.setJpaVendorAdapter(jpaVendorAdapter());
        ans.setPackagesToScan("org.inthemoon.train.chinese.data");
        return ans;
     }
  
     @Bean
     public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter ans = new HibernateJpaVendorAdapter();
        ans.setShowSql(false);
        ans.setGenerateDdl(true);
        ans.setDatabase(Database.H2);
        return ans;
     }
  
     @Bean
     public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
        JpaTransactionManager ans = new JpaTransactionManager();
        ans.setEntityManagerFactory(emf);
  
        return ans;
     }
  
  }
  </code></pre>
  
  <p>it cause the following exception</p>
  
  <pre><code>Exception in thread "main" org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
  ...
  </code></pre>
  
  <p>P.S. Is there any way to configure <code>IoC</code> from the first attempt?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am using following libs:</p>
  
  <pre><code>compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.5.Final'
  
  compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.10.5.RELEASE'
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I tried 8 different versions of <code>hibernate-core</code> to build with spring-jpa of <code>1.10.5.RELEASE</code>.</p>
  
  <p>Versions from <code>5.2.1</code> to <code>5.2.6</code> were causing the same exception</p>
  
  <pre><code>NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
  </code></pre>
  
  <p>Versions <code>5.1.3</code> and <code>5.0.11</code> were causing </p>
  
  <pre><code>ClassNotFoundException: org.hibernate.ejb.HibernateEntityManagerFactory
  </code></pre>
  
  <p>And the only version was causing something more complex was <code>5.2.0</code>. It was causing</p>
  
  <pre><code>SchemaManagementException: Attempt to resolve foreign key metadata from JDBC metadata failed to find column mappings for foreign key named [FKLOK22W31RKBMIIC2J96T9LTCN
  </code></pre>
  
  <p>The questions arose:</p>
  
  <p>1) Does this mean that namely version <code>5.2.0</code> is compatible with <code>1.10.5</code>?</p>
  
  <p>2) How would I know this without experiment?</p>
  
  <p>3) Is this normal to guess versions this way? Wasn't the purpose of dependency management tools to avoid such things? If <code>spring-data-jpa:1.10.5</code> depends on hibernate of <code>5.2.0</code> then why doesn't this described in it's <code>POM</code>?</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Out of the box example: <a href="https://github.com/dims12/TrySpringJpaPlusHibernate" rel="noreferrer">https://github.com/dims12/TrySpringJpaPlusHibernate</a></p>
  
  <p>It doesn't work.</p>