Spring + Hibernation: LocalSessionFactoryBean - NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext

I am trying to integrate Hibernate 4.0.0.FINAL with Spring 3.1.0.RELEASE using @Configuration .

Subsequently, this problem occurs:

 BeanCreationException: Error creating bean with name 'alertsSessionFactoryBean' NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext$Default.getDelimitedIdentifier()Ljava/lang/Boolean; 

This is my PersistenceHibernateConfig file

 @Configuration @EnableTransactionManagement public class PersistenceHibernateConfig { @Value("${jdbc.driverClassName}") private String driverClassName; @Value("${jdbc.url}") private String url; @Value("${hibernate.dialect}") String hibernateDialect; @Value("${hibernate.show_sql}") boolean hibernateShowSql; @Value("${hibernate.hbm2ddl.auto}") String hibernateHbm2ddlAuto; @Bean public LocalSessionFactoryBean alertsSessionFactoryBean() { final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(this.restDataSource()); sessionFactory.setPackagesToScan(new String[]{"com.cloudlb"}); sessionFactory.setHibernateProperties(this.hibernateProperties()); return sessionFactory; } @Bean public DataSource restDataSource() { final DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(this.driverClassName); dataSource.setUrl(this.url); dataSource.setUsername("test"); dataSource.setPassword("1234"); return dataSource; } @Bean public HibernateTransactionManager transactionManager() { final HibernateTransactionManager txManager = new HibernateTransactionManager(); txManager.setSessionFactory(this.alertsSessionFactoryBean().getObject()); return txManager; } @Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslationPostProcessor() { return new PersistenceExceptionTranslationPostProcessor(); } @Bean public PersistenceExceptionTranslator exceptionTranslator() { return new HibernateExceptionTranslator(); } final Properties hibernateProperties() { return new Properties() { { this.put("persistence.dialect", PersistenceHibernateConfig.this.hibernateDialect); this.put("hibernate.hbm2ddl.auto", PersistenceHibernateConfig.this.hibernateHbm2ddlAuto); this.put("hibernate.show_sql", PersistenceHibernateConfig.this.hibernateShowSql); } }; } } 

I think this may be a problem with LocalSessionFactoryBean, but I cannot figure out what is wrong. Maybe I missed something.

I found out that this is due to the lack of hibernate-annotation.jar, if it is 3.x I don’t know why in 4.0 annotation: org.hibernate.cfg.annotations.reflection.XMLContext is in the jar file of the hibernation file and there is still an error .

Thank you in advance

+6
source share
1 answer

OK This is very similar to the fact that you have problems with compatible versions of all the necessary dependencies. Here are a few thoughts on what might be wrong:

  • It doesn't look like you are using Maven or similar to manage your dependencies. It is highly recommended that you use an automatic tool to manage your dependencies, as it is very tough / error prone to provide all the necessary dependencies manually. In this case, you should be able to download the issue in a zip file containing all the necessary banks from here . Is that what you did?

  • The sleep core is dependent on hibernate-commons-annotations.jar. All annotations that were in sleep mode annotations have been in the kernel for some time. So you need hibernate-commons-annotations.jar, not hibernate-annotations.jar

+7
source

Source: https://habr.com/ru/post/904470/


All Articles