2

This is my configuration.

It says no such methods found but that does exist both in Java docs and also in my Util file. I read somewhere that it's cross configured with hibernate 3 and 4. Cant get this…

 <!DOCTYPE hibernate-configuration SYSTEM
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
            <session-factory>   


                <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="connection.url">jdbc:mysql://localhost/datacenter</property>
                <property name="connection.username">root</property>
                <property name="connection.password">admin</property>  


                <property name="dialect">org.hibernate.dialect.MySQLDialect</property>      
                <property name="current_session_context_class">thread</property>
                <property name="show_MySql">TRUE</property>
                <property name="format_sql">TRUE</property>
                <property name="jboss.as.jpa.providerModule">hibernate3-bundled</property>


                <property name="hibernate.hbm2ddl.auto">update</property>
                <property name="hibernate.cache.use_second_level_cache">true</property>
               <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property> 

                <!-- List of annotated classes-->
                <!-- Associations -->
                <!-- One to one -->
                <mapping class="Emp_Timecard" />
                <mapping class="maindoor" />
                <mapping class="serverroom" />
                <mapping class="timesheet" />
                <mapping class="hibernatepojos.Resource_list"/>


            </session-factory>
        </hibernate-configuration>

This is my Util file:

package hibernatedata;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

    private static SessionFactory sessionFactory;
    private static AnnotationConfiguration config1;

    static {
        config1 = (AnnotationConfiguration) new AnnotationConfiguration()
                .configure("hibernate.cfg.xml");

    }

    public static SessionFactory getSessionFactory() {
        if (sessionFactory == null) {

            createSessionfactory();
        } 
        return sessionFactory;

    }

    private static void createSessionfactory() {
        sessionFactory = config1.buildSessionFactory();

    }

    public static Session openSession() {

        return getSessionFactory().getCurrentSession();
    }

    public static void closeSessionFactory() {

        // getSessionFactory().close();
    }

    public static void save(Object o) {
        Session s = openSession();
        System.out.println("kejrkvg");
        s.beginTransaction();
        s.save(o);
        s.getTransaction().commit();
        // s.close();
        // s.clear();
        if (s.isOpen()) {

            s.close();
        }
        closeSessionFactory();
    }

    public static void delete(Object o) {
        Session s = openSession();
        s.beginTransaction();
        s.delete(o);
        s.getTransaction().commit();
        // s.close();
    }

    public static <T> T load(Class<T> clazz, int id) {
        Session s = openSession();
        s.beginTransaction();
        T t = clazz.cast(s.load(clazz, id));
        // s.getTransaction().commit();

        return t;

    }

    public static void update1(Object o) {
        Session s = openSession();
        s.beginTransaction();
        s.update(o);
        s.getTransaction().commit();
        // s.close();
    }

}
2
  • need to see your java code, where you are getting the error ?? Commented Jan 16, 2013 at 10:56
  • 1
    @user1979730 check your project libraries. It seems that there are more than one hibernate version library in your classpath. See also: stackoverflow.com/questions/4324068/… Commented Jan 16, 2013 at 12:55

2 Answers 2

1

It says no such methods found but thta does well exsists in Java docs

The error is generated at runtime, not when compiling the code. So t looks like some of your code was compiled against one version of the code, but gets executed agains a different and probably older version. The full stack trace will contain more information about where the incompatibility lies.

If in doubt, you can use javap to see whether a class loaded from a given class path on a given system actually contains that method or not. If the classpath you expect to be used does not provide that method, you might need to get the correct version of the library installed into that path. If on the other hand it looks correct there as well, then this is a good indication that the a different class gets loaded than the one you expect. You could then add debug code to determine the class loader used to load that class, to see where it actually came from.

Sign up to request clarification or add additional context in comments.

Comments

0

The accepted answer for question java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session may also provide some insight - "In Hibernate 3.6 the SessionFactory.openSession no longer returns an org.hibernate.classic.Session, rather it returns an org.hibernate.Session. This is a refactor that breaks client code.."

1 Comment

How to fix this issue but

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.