Hello, I'm trying to run the simple HelloWorld examples in the
Java Persistence With Hibernate (Manning 06)
I was successful in running the Hello World Message example using XML mapping, but when I switched over to annotations, I get the following exception. Any ideas on why I get the ClassFormatException?
Code:
14:22:00,468 DEBUG [main] cfg.Configuration (Configuration.java:1282) - Preparing to build session factory with filters : {}
14:22:00,468 DEBUG [main] cfg.AnnotationConfiguration (AnnotationConfiguration.java:235) - Execute first pass mapping processing
14:22:00,531 DEBUG [main] cfg.AnnotationConfiguration (AnnotationConfiguration.java:435) - Process hbm files
14:22:00,531 DEBUG [main] cfg.AnnotationConfiguration (AnnotationConfiguration.java:443) - Process annotated classes
Exception in thread "main" java.lang.ExceptionInInitializerError
at hibernate.scratchpad.persistence.HibernateUtil.<clinit>(HibernateUtil.java:15)
at hibernate.scratchpad.hello.HelloWorld.main(HelloWorld.java:23)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/InheritanceType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at org.hibernate.cfg.InheritanceState.extractInheritanceType(InheritanceState.java:51)
at org.hibernate.cfg.InheritanceState.<init>(InheritanceState.java:21)
at org.hibernate.cfg.AnnotationBinder.buildInheritanceStates(AnnotationBinder.java:2058)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:446)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at hibernate.scratchpad.persistence.HibernateUtil.<clinit>(HibernateUtil.java:12)
... 1 more
The code for Message.java is:
Code:
package hibernate.scratchpad.hello.annotations;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "MESSAGES")
public class Message {
@Id @GeneratedValue
@Column(name = "MESSAGE_ID")
private Long id;
@Column(name = "MESSAGE_TEXT")
private String text;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "NEXT_MESSAGE_ID")
private Message nextMessage;
etc.
The snippet from HibernateUtil:
Code:
static {
try {
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
//sessionFactory = new Configuration().configure().buildSessionFactory();
} catch(Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
..and the only mapping entry i have in hibernate.config.xml ->
Code:
<mapping class="hibernate.scratchpad.hello.annotations.Message"/>
[/u]