File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes getting NoSuchMethodException when trying to use EJB 3.0 Persistence with annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "getting NoSuchMethodException when trying to use EJB 3.0 Persistence with annotations" Watch "getting NoSuchMethodException when trying to use EJB 3.0 Persistence with annotations" New topic
Author

getting NoSuchMethodException when trying to use EJB 3.0 Persistence with annotations

Gaurav Saxena
Greenhorn

Joined: May 28, 2002
Posts: 29
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?

Regards
Gaurav


Gaurav Saxena<br />Programmer Analyst<br />Portland, Oregon
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

No such method, eh?

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:

Classloaders Demystified

Where is the jar file that has this package: javassist.bytecode? Could there be more than one?

-Cameron McKenzie

[ April 27, 2008: Message edited by: Cameron Wallace McKenzie ]
[ June 23, 2008: Message edited by: Cameron Wallace McKenzie ]
Gaurav Saxena
Greenhorn

Joined: May 28, 2002
Posts: 29
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
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

To be honest, it looks like a file from a package called:

javassist.bytecode.annotation

I don't think that has anything to do with the files you download from Hibernate, does it? What are you using javaassist for?

I've got a tutorial that helps you get up and running without having to use ANT at all - just the JDK and a database.

A Basic Hibernate Development Environment WITHOUT ANT

Sometiems it's good to get back to basics.

-Cameron McKenzie
Gaurav Saxena
Greenhorn

Joined: May 28, 2002
Posts: 29
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.
.
Gaurav Saxena
Greenhorn

Joined: May 28, 2002
Posts: 29
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.

download javaassist url : http://www.java2s.com/Code/Jar/jboss-5.0.0.Beta2/Downloadjavassistjar.htm

Cheers!
Gaurav
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting NoSuchMethodException when trying to use EJB 3.0 Persistence with annotations