Recently, I created a Maven project in which I created the following files
- Model Class
- Calling Class ( Instantiates Model Class object and create Session factory)
Hibernate.cfg.xml file
org.postgresql.Driver jdbc:postgresql://localhost:8080/dev temp temp 1
<!-- SQL Dialect --> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> <property name="hbm2ddl.auto">create</property> <!-- Names the annotated entity class --> <!-- List of XML mapping files --> <mapping class="org.test.livejava.machine.UserDetails" />
Added the following dependencies in Maven.
UTF-8
JBoss repository http://repository.jboss.org/nexus/content/groups/public/ junit junit 3.8.1 org.codehaus.mojo hibernate3-maven-plugin 2.0 org.slf4j slf4j-api 1.7.6 compile org.postgresql postgresql 9.3-1100-jdbc41
<dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> </dependency> <!-- Hibernate annotation --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.6.3.Final</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.12.1.GA</version> </dependency>
Now, when I run the program and run it, it gives me the following error.
19:04:12,784 INFO org.hibernate.cfg.Environment - Hibernate 3.2.0.cr5
19:04:12,786 INFO org.hibernate.cfg.Environment - hibernate.properties not found
19:04:12,787 INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
19:04:12,789 INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
19:04:12,818 INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
19:04:12,818 INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="org.test.livejava.machine.UserDetails"/>
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1524)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at org.test.livejava.machine.machine.main(machine.java:29)
After reading about the deprecated Configuration method, I used AnnotationsConfiguration() and it started giving me the following error.
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.test.livejava.machine.machine.main(machine.java:29)
Has anyone got the same issue before while compiling? I am not sure why this is not able to find load it correctly even though all the maven dependencies seem to be included
I appreciate your time and help looking into it!
Thanks!