-->
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.  [ 9 posts ] 
Author Message
 Post subject: java.lang.NoSuchMethodError
PostPosted: Thu May 06, 2010 4:07 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
Hello, I'm studing the book of Java Manning but that forum is closed, and I have a doubt. I have one error to use EntityManagerFactory:

Quote:
[java] 09:38:34,029 DEBUG AnnotationConfiguration:489 - Process annotated classes
[java] 09:38:34,029 DEBUG AnnotationConfiguration:375 - processing manytoone fk mappings
[java] Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationConfiguration.getReflectionManager()Lorg/hibernate/reflection/ReflectionManager;
[java] at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:156)
[java] at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
[java] at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
[java] at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
[java] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Java Result: 1
BUILD SUCCESSFUL


I don't know what to do now, what means "java.lang.NoSuchMethodError"? Shortness a method in the library? Please, can someone help me?

Thanks very much,


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Fri May 07, 2010 4:23 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
According the javadoc this error can only occur at run time if the definition of a class has incompatibly changed.

You are probably using incompatible hiberante jar files.
Which version of hibernate are you using ?


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Fri May 07, 2010 5:53 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
I use following libraries in my lib:
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
c3p0-0.9.1.jar
cglib-2.2.jar
commons-collections-3.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
freemarker.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-tools.jar
hibernate-validator-3.0.0.ga.jar
hibernate3.jar
hsqldb.jar
javassist.jar
jboss-archive-browsing.jar
jta-1.1.jar
log4j-1.2.15.jar
slf4j-api-1.5.3.jar
slf4j-jdk14-1.4.2.jar
validation-api-1.0.0.Ga.jar

If this is not the error, I have reading in internet and it can be that I need the following library: hibernate-jpa-util.jar, but I can not find it and download. Whether a thing as if other, I appreciate your help.

Thank you very much,


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Fri May 07, 2010 10:01 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
The question is, of which version your hibernate3.jar is.
Is it is a 3.5 version, then you must remove
hibernate-annotations.jar and hibernate-entitymanager.jar from your classpath
as in version 3.5 hibernate-annotations and hibernate-entitymanager are included in the hibernate3.jar.


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Mon May 10, 2010 3:01 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
Hello, I think I have 3.0 version of hibernate3.jar, because inside of it I there are for example hibernate-configuration-3.0.dtd and hibernate-mapping-3.0.dtd.
Also I have tried to remove hibernate-entitymanager.jar and I have one error because it is missig, and I have tried to remove hibernate-annotations.jar and I have this error:

Quote:
Buildfile: C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
[mkdir] Created dir: C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
compile:
[javac] Compiling 2 source files to C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
copymetafiles:
[copy] Copying 2 files to C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration
[java] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
[java] at java.net.URLClassLoader$1.run(Unknown Source)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClassInternal(Unknown Source)
[java] ... 3 more
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 2 seconds


So I need the class "org.hibernate.cfg.AnnotationConfiguration that is missing", isn't it? And I don't know where to find it.

I appreciate your help, thank you very much


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Mon May 10, 2010 8:15 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As you use Hibernate for studing purpose, why not use the most recent hibernate version 3.5 ?
You can download the 3.5 distribution bundle from the hibernate site and, as said, it has fewer jar-files
to handle as prior versions, so I'm pretty sure you will get rid of the NoSuchMethodError problem.


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Mon May 10, 2010 9:53 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
Hello, I have removed hibernate-annotations.jar, hibernate3.jar and hibernate-entitymanager.jar, and I have added hibernate-core-3.5.0-CR-2.jar, but now I have another error:

Quote:
Buildfile: C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
[mkdir] Created dir: C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
compile:
[javac] Compiling 2 source files to C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
copymetafiles:
[copy] Copying 2 files to C:\Documents and Settings\empalacios\workspaceManningJP\HelloWorldJPEM\bin
run:
[java] Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named helloworld
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 second


and my persistence-unit is "helloworld", this is my persistence.xml:

Code:
<!-- La cabecera de este fichero declara el esquema que se va a utilizar, y que será
   siempre el mismo, aunque se omita en el manual -->
   
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
   version="1.0">
   
   <persistence-unit name="helloworld">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <!-- Not needed, Hibernate supports auto-detection in JSE
      <class>hello.Message</class>-->
      <properties>
         <property name="hibernate.archive.autodetection" value="class, hbm"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.connection.driver_class"
            value="org.hsqldb.jdbcDriver"/>
         <property name="hibernate.connection.url"
            value="jdbc:hsqldb:hsql://localhost"/>
         <property name="hibernate.connection.username" value="sa"/>
         <property name="hibernate.c3p0.min_size" value="5"/>
         <property name="hibernate.c3p0.max_size" value="20"/>
         <property name="hibernate.c3p0.timeout" value="300"/>
         <property name="hibernate.c3p0.max_statements" value="50"/>
         <property name="hibernate.c3p0.idle_test_period"
            value="3000"/>
         <property name="hibernate.dialect"
            value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create"/>
      </properties>
   </persistence-unit>

</persistence>


and this is my HelloWorld.java:

Code:
package hello;

import java.util.*;
import javax.persistence.*;

public class HelloWorld {

   @SuppressWarnings("unchecked")
   public static void main(String[] args) {

      //Inicio del EntityManagerFactory, crea la unidad de persistencia
      //Utilizando un hibernate.cfg.xml del primer HelloWorld, bastaría con: EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld");
      Map myProperties = new HashMap();
      myProperties.put("hibernate.hbm2ddl.auto", "create-drop");
      EntityManagerFactory emf =
      Persistence.createEntityManagerFactory("helloworld", myProperties);

      
      //Primera unidad de trabajo
      EntityManager em = emf.createEntityManager();
      EntityTransaction tx = em.getTransaction();
      tx.begin();
      Message message = new Message("HelloWorld");
      em.persist(message);
      tx.commit();
      em.close();
      
      //Segunda unidad de trabajo
      EntityManager newEm = emf.createEntityManager();
      EntityTransaction newTx = newEm.getTransaction();
      List messages = newEm.createQuery("select m from Message m order by m.text asc").getResultList();
      System.out.println(messages.size()+"message(s) found:");
      for (Object m : messages)
      {
         Message loadedMsg = (Message) m;
         System.out.println(loadedMsg.getText());
      }
      newTx.commit();
      newEm.close();
      
      //Cerrando la aplicación
      emf.close();
   }

}


Please, can you help me and tell me where is the error now?

Thank you very much


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Wed May 12, 2010 10:55 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
1.) persistence.xml must be placed in a folder named META-INF
2.) In order that the file persistence.xml is correctly located you can either
- pack META-INF/persistence.xml into a jar-file and add this jar-file to your java-classpath
or
- include the parent folder of META-INF into your java-classpath


Top
 Profile  
 
 Post subject: Re: java.lang.NoSuchMethodError
PostPosted: Thu May 13, 2010 3:14 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
Hello, my persistence.xml is in META-INF path, and I have included META-INF in classpath but I have the same error. Perhaps I am doing something wrong.

This is the structure of my folders:

Quote:
HelloWorldJPEM (project)
+bin (folder)
hello (folder inside bin)
HelloWorld.class (inside hello)
Message.class (inside hello)
+etc (folder)
META-INF (folder inside etc)
persistence.xml (inside META-INF)
log4j.properties (inside etc)
+lib (folder)
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
c3p0-0.9.1.jar
cglib-2.2.jar
commons-collections-3.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
freemarker.jar
hibernate-commons-annotations.jar
hibernate-core-3.5.0-CR-2.jar
hibernate-tools.jar
hibernate-validator-3.0.0.ga.jar
hsqldb.jar
javassist.jar
jboss-archive-browsing.jar
jta-1.1.jar
log4j-1.2.15.jar
slf4j-api-1.5.3.jar
slf4j-jdk14-1.4.2.jar
validation-api-1.0.0.Ga.jar
+src (folder)
hello (folder inside src)
HelloWorld.java (inside hello)
Message.java (inside hello)
.classpath
.project
.refactor
build.xml
test.log
test.properties
test.script


and this is my .classpath:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
   <classpathentry kind="src" path="src"/>
   <classpathentry kind="etc" path="etc/META-INF"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
   <classpathentry kind="lib" path="lib/ejb3-persistence.jar"/>
   <classpathentry kind="lib" path="lib/hibernate-commons-annotations.jar"/>
   <classpathentry kind="lib" path="lib/hibernate-tools.jar"/>
   <classpathentry kind="lib" path="lib/hsqldb.jar"/>
   <classpathentry kind="lib" path="lib/hibernate-validator-3.0.0.ga.jar"/>
   <classpathentry kind="lib" path="lib/validation-api-1.0.0.GA.jar"/>
   <classpathentry kind="lib" path="lib/jboss-archive-browsing.jar"/>
   <classpathentry kind="lib" path="lib/hibernate-core-3.5.0-CR-2.jar"/>
   <classpathentry kind="output" path="bin"/>
</classpath>


and the error is the same:
Quote:
"Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named helloworld
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Java Result: 1"

Moreover, by introducing line "<classpathentry kind="etc" path="etc/META-INF"/>", eclipse show me one error (it shows a red cross at the height of the project name).

Could the error in the main of HelloWorld.java? Would be remiss to create an EntityManager named "helloworld"?

Thank you very much for your help


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.