SSCCE est ici: https://github.com/dims12/TrySpringJpaPlusHibernateComment trouver la paire de versions compatibles d'Hibernate + Spring-JPA? (Impossible d'ouvrir JPA EntityManager pour la transaction)
Je suis en train de courir sans printemps JPA persistence.xml et ont la configuration suivante:
@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;
}
}
il cause l'exception suivante
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 Est-il possible de configurer IoC
dès la première tentative?
MISE À JOUR
J'utilise libs suivants:
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'
MISE À JOUR 2
J'ai essayé 8 différentes versions de hibernate-core
pour construire avec ressort JPA de 1.10.5.RELEASE
.
versions de 5.2.1
-5.2.6
étaient à l'origine de la même exception
NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
Versions 5.1.3
et 5.0.11
provoquaient
ClassNotFoundException: org.hibernate.ejb.HibernateEntityManagerFactory
Et la seule version était plus complexe causant quelque chose était 5.2.0
. Il était à l'origine
SchemaManagementException: Attempt to resolve foreign key metadata from JDBC metadata failed to find column mappings for foreign key named [FKLOK22W31RKBMIIC2J96T9LTCN
Les questions ont été soulevées:
1) Est-ce que cela signifie que la version à savoir 5.2.0
est compatible avec 1.10.5
?
2) Comment le saurais-je sans expérience?
3) Est-ce normal de deviner les versions de cette façon? Le but des outils de gestion de la dépendance n'était-il pas d'éviter de telles choses? Si spring-data-jpa:1.10.5
dépend de l'hibernation de 5.2.0
alors pourquoi cela n'est-il pas décrit dans POM
?
MISE À JOUR 3
Sur l'exemple de la boîte: https://github.com/dims12/TrySpringJpaPlusHibernate
Il ne fonctionne pas.
Version incompatible de JPA et Hibernate – shazin
@shazin comment trouver la paire compatible? – Dims
Il semble que hibernate 5.2.x soit supporté par la ligne 1.10.x de spring-data-jpa basée sur le fichier pom pour spring-data-jpa: https://github.com/spring-projects/spring-data- jpa/blob/1.10.x/pom.xml – LucasP