-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Hibernate annotations gives me a NoSuchMethodError exception
PostPosted: Sat Sep 20, 2008 10:44 am 
Newbie

Joined: Tue Sep 16, 2008 1:56 am
Posts: 5
Hi

I am using the latest version of hibernate

hibernate-distribution-3.3.1 GA

hibernate-annotations-3.4.0 GA

hibernate-tools-3.2.2 Beta 1


I have annotated java entity files that i have mapped in my hibernate.cfg.xml as follows..

Code:
<?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="connection.datasource">java:comp/env/jdbc/Test</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>

    <property name="hibernate.hbm2ddl.auto">create-drop</property>
    <property name="hibernate.format_sql">true</property>
    <mapping class="com.vo.entity.Group"/>
    <mapping class="com.vo.entity.GroupAddress"/>
    <mapping class="com.vo.entity.GroupUsers"/>
    <mapping class="com.vo.entity.User"/>
   <!-- Similarly more mapping classes/-->
  </session-factory>
</hibernate-configuration>


My project compiles fine, but when i run the project, i get the following error..

Code:
java.lang.NoSuchMethodError: org.hibernate.util.ReflectHelper.classForName(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:800)
        at com.util.db.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:27)
        at com.util.db.UserDB.insertUser(UserDB.java:50)


My util class is something like this..

Code:
public class HibernateUtil {
    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml)
            // config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception.
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

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

}



Could some one please tell me whats wrong with this and why i am getting the above exception?? Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 11:08 am 
Newbie

Joined: Fri Sep 19, 2008 10:26 am
Posts: 8
I am having the same problem with hibernate-search.

view my post: http://forum.hibernate.org/viewtopic.php?t=990785

I think the problem is becouse projects that were in hibernate-core are now new indipendent projects and other projects like annotation in the future will be part of the hibernate core.
We are in a transactonal moment.
I think we both need to find the right libraries configuration and versions.


Last edited by violix on Sun Sep 21, 2008 2:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 1:05 pm 
Newbie

Joined: Tue Sep 16, 2008 1:56 am
Posts: 5
Thanks violix..

I was able to open the sources in hibernate (the specified class is a part of hibernate3.jar) and see that a method and return type of the class mentioned in the error actually existed. So i am not sure why it has not been picked up.. Maybe i am missing a configuration or doing something wrong with the config. somewhere?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 1:44 pm 
Newbie

Joined: Fri Sep 19, 2008 10:26 am
Posts: 8
I still think it's a dependecy issue...it looks for this class and method in the wrong place.
try other versions of hibernate core and annotation.
are you using jboss?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 2:40 pm 
Newbie

Joined: Tue Sep 16, 2008 1:56 am
Posts: 5
Yes.. should be a dependency issue.. If some one has tried this out before and knows the exact minor versions to be used against the other set, then it would be very usefull. I am using tomcat 6.0.16.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 12:21 am 
Beginner
Beginner

Joined: Thu Sep 11, 2008 5:33 am
Posts: 28
Can you please paste the detailed log. :)

I think it would be helpful to trace the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 8:59 am 
Newbie

Joined: Fri Sep 19, 2008 10:26 am
Posts: 8
I think you will solve the problem mapping your pojo using xml instead of annotation.
If you want to use annotation you need a META-INF/persistence.xml and use EntityManager to query your database.
I prefer the second option.
http://www.hibernate.org/397.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.