0

Recently, I created a Maven project in which I created the following files

  1. Model Class
  2. Calling Class ( Instantiates Model Class object and create Session factory)
  3. 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" />
    

  4. 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!

1 Answers1

1

Your Maven dependency lists a Hibernate version of 3.6.3.Final, but your logs indicate a Hibernate version of 3.2.0.cr5 (note that even if you need to stay with Hibernate 3, the bugfixes are up to 3.6.10).

The problem is attempting to use an ancient version of Hibernate at runtime: You either aren't using Maven to launch the program, or you're not compiling it into a fat war or jar.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • Thank you for your time to look into it. I had changed my hibernate version from 3.6.3 Final to 4.0.1 Final version. Also, all the dependencies are correct in the pom.xml. I do not get this error anymore. Thanks again! – startedFromTheBottom Feb 23 '14 at 16:18