I get an exception when I try to build a session factory object. My hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=lotusinvest_db</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password">123456</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
  </session-factory>
</hibernate-configuration>

The HibernateConfiguration class:

public class HibernateConfiguration {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        SessionFactory SessionFactory = null;
        try {
            Configuration configuration = new Configuration();
            configuration.configure();
            StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
            StandardServiceRegistry registry=ssrb.build();
            SessionFactory = configuration.buildSessionFactory(registry);
        } catch (Throwable ex) {
            System.err.println("Failed to create sessionFactory object." + ex);
            ex.printStackTrace();
        }
        return SessionFactory;
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static Session openSession() {
        return sessionFactory.openSession();
    }

    public static void shutdown() {
        getSessionFactory().close();
    }

    public static void main(String[] args) {
    }
}

When I try to run the programme, I am getting the exception java.lang.AbstractMethodError at the line SessionFactory = configuration.buildSessionFactory(registry). How can I fix it?

share|improve this question
    
Plz add full stack trace? – Bikku Aug 23 '15 at 21:22
    
Were you able to solve this? I am having this same problem too. – Luís de Sousa Feb 19 '16 at 8:30
    
Your Class 'SessionFactory' and the instance variable 'SessionFactory' should not be the same. Change the instance variable to 'sessionFactory' (start with lowercase_ – muttonUp May 28 '16 at 22:58

Your Class and you instance variable are identical. I've renamed the instance

private static SessionFactory buildSessionFactory() {
    SessionFactory sessionFactoryInstance = null;
    try {
        Configuration configuration = new Configuration();
        configuration.configure();
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
        StandardServiceRegistry registry=ssrb.build();
        sessionFactoryInstance = configuration.buildSessionFactory(registry);
    } catch (Throwable ex) {
        System.err.println("Failed to create sessionFactory object." + ex);
        ex.printStackTrace();
    }
    return sessionFactoryInstance;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.