Spring + Hibernate: LocalSessionFactoryBean – NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext


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

Afterwards, 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

public class PersistenceHibernateConfig {

    private String driverClassName;

    private String url;

    String hibernateDialect;

    boolean hibernateShowSql;

    String hibernateHbm2ddlAuto;

    public LocalSessionFactoryBean alertsSessionFactoryBean() {
        final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setPackagesToScan(new String[]{"com.cloudlb"});
        return sessionFactory;

    public DataSource restDataSource() {
        final DriverManagerDataSource dataSource = new DriverManagerDataSource();

        return dataSource;

    public HibernateTransactionManager transactionManager() {
        final HibernateTransactionManager txManager = new HibernateTransactionManager();

        return txManager;

    public PersistenceExceptionTranslationPostProcessor exceptionTranslationPostProcessor() {
        return new PersistenceExceptionTranslationPostProcessor();

    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 it could be a problem with LocalSessionFactoryBean but I can’t understand what is wrong. I may be missing something.

I found out that it is because of missing hibernate-annotation.jar if it is 3.x
Don’t know why in 4.0 the annotation: org.hibernate.cfg.annotations.reflection.XMLContext is in hibernate-core jar file and it still error.


OK This sounds a lot like you’re having issues providing compatible versions of all of the required dependencies. Here are a few thoughts on what could be wrong:

  1. It doesn’t sound like you’re using Maven or similar to manage your dependencies. Using an automatic tool to manage your dependencies is strongly recommended since it’s very hard/error prone to provide all of the required dependencies manually. That said you should be able to download the release in a zip file containing all the required jars from here. Is this what you did?

  2. Hibernate core depends on hibernate-commons-annotations.jar. All the annotations which were in hibernate-annotations have been in the core jar for a while now. So you need hibernate-commons-annotations.jar not hibernate-annotations.jar

Answered By – Alex Barnes

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published