SSCCE here: https://github.com/dims12/TrySpringJpaPlusHibernate
I am trying to run Spring JPA without persistence.xml and have the following configuration:
@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;
}
}
it raises the following exception
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;
...
PS Is there a way to configure IoCon the first try?
UPDATE
I use the following libs:
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'
UPDATE 2
I tried 8 different hibernate-corebuild versions with spring-jpa from 1.10.5.RELEASE.
Versions from 5.2.1to 5.2.6cause the same exception
NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
Versions 5.1.3and 5.0.11called
ClassNotFoundException: org.hibernate.ejb.HibernateEntityManagerFactory
And the only version that evoked something more complex: 5.2.0. It caused
SchemaManagementException: Attempt to resolve foreign key metadata from JDBC metadata failed to find column mappings for foreign key named [FKLOK22W31RKBMIIC2J96T9LTCN
There are questions:
1) , 5.2.0 1.10.5?
2) ?
3) ? ? spring-data-jpa:1.10.5 5.2.0, POM?
3
: https://github.com/dims12/TrySpringJpaPlusHibernate
.