Hi All I am new to hibernate and EJB 3.0 persistence. Getting following error when i try to run the example from 2nd chapter of book EJB 3.0 persistence with hibernate
Exception in thread "main" java.lang.NoSuchMethodError: javassist.bytecode.AnnotationsAttribute.getAnnotation(Ljava/lang/String Ljavassist/bytecode/annotation/Annotation; [java] at org.hibernate.ejb.packaging.JarVisitor.checkAnnotationMatching(JarVisitor.java:342) [java] at org.hibernate.ejb.packaging.JarVisitor.executeJavaElementFilter(JarVisitor.java:298) [java] at org.hibernate.ejb.packaging.JarVisitor.addElement(JarVisitor.java:259) [java] at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:54) [java] at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:62) [java] at org.hibernate.ejb.packaging.ExplodedJarVisitor.doProcessElements(ExplodedJarVisitor.java:45) [java] at org.hibernate.ejb.packaging.JarVisitor.getMatchingEntries(JarVisitor.java:241) [java] at org.hibernate.ejb.Ejb3Configuration.addMetadataFromVisitor(Ejb3Configuration.java:271) [java] at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240) [java] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120) [java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51) [java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33) [java] at hello.HelloWorld.session1(Unknown Source) [java] at hello.HelloWorld.main(Unknown Source) [java] Java Result: 1
There is no compilation error. Am i missing some jar file?
You may have the wrong version of the jar file you need in order to get your examples running. I believe the book you are learning provides a file called javaassist.jar. This file is supposed to make things much easier for you, although with the number of people reporting problems with this jar file, I'd say that it's made life alot more miserable for people than it's helped.
Man, I hate that error. It means that the JVM has loaded a class, but the class it loaded doesn't have the method that is needed. Strange, eh?
My guess is that you have multiple versions of a common jar file on your classpath. The JVM is loading an earlier version of the class that does not have the new, updated method. What's more frustrating is that you probably don't have the problem at compile time - that is, your compile time environment is running properly.
Here's a quick tutorial on classloaders and the classloader hierarchy:
thanks for the reply! Yeah I think I got too many jars in my lib and probably JVM is picking up one that it is not supposed to pick up. Anyways, I am doing this hibernate thing for the first time and did'nt have no idea about the jars to be used so put a lot of jar files in lib. Here is a list ant-1.6.5.jar ant-antlr-1.6.5.jar ant-junit-1.6.5.jar ant-launcher-1.6.5.jar antlr.license.txt antlr-2.7.6.jar ant-swing-1.6.5.jar apache.license.txt apache.license-2.0.txt asm.jar asm-attrs.jar c3p0.license.txt c3p0-0.9.1.jar cglib-2.1.3.jar checkstyle-all.jar classes12.zip cleanimports.jar commons-collections-2.1.1.jar commons-logging-1.0.4.jar concurrent-1.3.2.jar connector.jar connector.licence.txt dom4j-1.6.1.jar ehcache-1.2.3.jar ejb3-persistence.jar hibernate3.jar hibernate-annotations.jar hibernate-commons-annotations.jar hibernate-entitymanager.jar hibernate-tools.jar hsqldb.jar javassist.jar jboss-common.jar jta.jar log4j-1.2.11.jar mysql-connector-java-5.1.5-bin.jar xml-apis.jar
I dont know which ones are the required ones and which ones are redundant. Using eclipse 3.2.2 and Ant to build and run the helloworld example. Can you please let me know which jar files can be removed from the above list? And thanks a tonne for the response Cameron!
Cameron Wallace McKenzie
author and cow tipper
I am on the basics itself. I have no idea what this file does, but without it it was throwing some other runtime exception. And in some forum it was suggested to put this file in the classpath. SO that exception was gone, and this new exception was thrown at runtime. I guess javassist is required for using Java Persistence API with Annotated classes. I am trying that helloworld example in 2nd chapter of Java Persistence with Hibernate book. Finished of the basic helloworld thing using hibernate. Moved on to trying the same helloworld thing using Java Persistence and hibernate using annotations . Thats where I am stuck for a long long time. .
Joined: May 28, 2002
Ok I got it running.It took a while to figure out what the issue was.... The Verion of javaassist.jar that i was using was an old one. Downloaded the latest version from this url and replaced the old one with the new one lib directory and it started working.