Ich versuche, Frühling Version 4.3.1 mit Hibernate 5 zu konfigurieren, aber ich habe Fehler, wenn Sie versuchen, Entity Manager Factory zu erstellen.configure spring4 with hibernate5
Meine Hibernate Version 5.0.9.Final“ Hibernate Validator Version "5.2.4.Final"
Meine Abhängigkeiten
- Hibernate-core 5.0.9.Final
- hibernate- EntityManager 5.0.9.Final
- Hibernate-ehcache 5.0.9
- Hibernate-Validator 5.2.4.Final
- Hibernate-JPA-2.1-api 1.0.0.Final
- validation-api 1.0.0.GA
das ist meine Konfiguration:
@Configuration
@EnableTransactionManagement
public class JpaConfiguration {
@Value("classpath:hibernate.properties")
private Properties jpaProperties;
@Resource(name = "dataSource")
private DataSource dataSource;
/**
* Enable exception translation for beans annotated with @Repository
*/
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
/**
* @see read http://www.springframework.org/docs/reference/transaction.html
*/
@Bean
public JpaTransactionManager transactionManager() {
return new JpaTransactionManager();
}
/**
* Build the entity manager with Hibernate as a provider.
*/
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(dataSource);
// We set the persistenceXmlLocation to a different name to make it work on JBoss.
emf.setPersistenceXmlLocation("classpath:META-INF/spring-persistence.xml");
emf.setPersistenceUnitName("myPU");
emf.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
emf.setJpaProperties(jpaProperties);
emf.setJpaDialect(new HibernateJpaDialect());
return emf;
}
@Bean
public SessionFactory sessionFactory(HibernateEntityManagerFactory entityManagerFactory) {
return entityManagerFactory.getSessionFactory();
}
}
und ich habe eine Fehlermeldung anzeigt:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.xxx.configuration.JpaConfiguration: Invocation of init method failed; nested exception is java.lang.AbstractMethodError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.xxx.Boot$.main(Boot.scala:44)
at com.xxx.Boot.main(Boot.scala)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.AbstractMethodError
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 18 more
Aber wenn ich meine Hibernate-Version von 5 bis 4 ändern, funktioniert alles gut.
Resolve:
Das Problem mit org.jadira.usertype“ "usertype.core" war, und ich habe Mismatch bekam mit Hibernate Version 4 und 5
Welche * genaue * Hibernate-Version ... Fügen Sie die Abhängigkeiten hinzu, die Sie verwenden. –
Scheint wie ein typischer Fehler, wenn Sie einen Mix-Mash aus Hibernate 4 und Hibernate 5-Jars im Klassenpfad haben. – Gimby
Meine Hibernate-Version ist 5.0.9.Final- und Hibernate-Validator 5.2.4.Final –