-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bad version number in .class file
PostPosted: Fri May 16, 2008 8:54 pm 
Newbie

Joined: Tue May 13, 2008 7:22 pm
Posts: 2
Location: Cambridge, MA
Hello,

I am getting a java.lang.UnsupportedClassVersionError: Bad version number in .class file Exception.

Hibernate version:
I'm using hibernate-3.2 on a Mac OS X 10.5.2 with the following java and javac (pre-installed by Apple):
$ java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)
$ javac -version
javac 1.5.0_13

Code leading to sessionFactory:
I'm trying to run the following simple Hibernate class:

package com.herenow.dataaccess;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
....

public class Setup0
{
public static void main(String[] args) throws IOException {
Setup0 s0 = new Setup0();
s0.populateFIPS();
}
public void populateFIPS() throws IOException {
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sessionFactory = cfg.buildSessionFactory(); <<<== line 56; Exception here
Session session = sessionFactory.getCurrentSession();

...code to load some data ...
session.getTransaction().commit();
}

Mapping documents:
The relevant part of my hibernate.cfg.xml file is:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost</property>
<property name="connection.username">hnmdatamanager</property>
<property name="connection.password">intheclear</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>

....<mapping resources.....

</session-factory>
</hibernate-configuration>

Name and version of the database you are using:
I am using PostgreSQL 8.3.1 with the postgresql-8.3-603.jdbc4.jar.

I am running this from ant 1.7 with a target "setup" as follows:
<target name="setup" depends="compile">
<java classname="com.herenow.dataaccess.Setup0">
<classpath>
<path refid="project.class.path"/>
<pathelement location="classes"/>
</classpath>
</java>
</target>

Full stack trace of any exception that occurs:
I am getting a java.lang.UnsupportedClassVersionError: Bad version number in .class file Exception as follows:

[java] java.lang.UnsupportedClassVersionError: Bad version number in .class file
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:747)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:201)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:104)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[java] Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
[java] at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1130)
[java] at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1307)
[java] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1371)
[java] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1324)
[java] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1078)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(Class.java:164)
[java] at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:57)
[java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[java] at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
[java] at com.herenow.dataaccess.Setup0.populateFIPS(Setup0.java:56) <<<== My Class
[java] at com.herenow.dataaccess.Setup0.main(Setup0.java:23)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)

I believe that the jre 1.5.0_13 and javac 1.5.0_13 (pre-installed by Apple) are the only java on the system.
Can anyone help me determine what is going wrong here?
Many thanks in advance,
Ken Bowen


Top
 Profile  
 
 Post subject: Getting the same problem but works in Eclipse
PostPosted: Fri May 23, 2008 12:49 pm 
Newbie

Joined: Fri May 23, 2008 12:45 pm
Posts: 2
I'm getting the same issue as Ken. Somewhere there must be two Postgres drivers, but I can't seem to find any conflicts. Is this a Postgres issue?

gene


Top
 Profile  
 
 Post subject: Using JDBC3 driver fixes the issue
PostPosted: Fri May 23, 2008 1:01 pm 
Newbie

Joined: Fri May 23, 2008 12:45 pm
Posts: 2
http://jdbc.postgresql.org/download.html#others

Here they don't say that you NEED JDK1.6 for the jdbc4 driver, but I suppose it's implied, because they say IF you are using jdk1.6 you should use the jdbc4 one.

I used the jdbc3 one instead:

http://jdbc.postgresql.org/download/pos ... .jdbc3.jar

and it solved this issue. My setup is the same as Ken in terms of postgres, mac OS, hibernate, and ant versions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.