[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2506
  • Last Modified:

Hibernate Example issue

Hi,

I am trying to riun hibernate one-one mapping example from link
http://www.vaannila.com/hibernate/hibernate-example/hibernate-tools-1.html

When i execute main.java getting following console message

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.java.lang.UnsupportedClassVersionError: (org/hsqldb/jdbcDriver) bad major version at offset=6
Exception in thread "main" java.lang.ExceptionInInitializerError
      at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
      at java.lang.J9VMInternals.initializeImpl(Native Method)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:177)
      at com.vaannila.student.Main.main(Main.java:12)
Caused by: java.lang.UnsupportedClassVersionError: (org/hsqldb/jdbcDriver) bad major version at offset=6
      at java.lang.ClassLoader.defineClassImpl(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:223)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:148)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:556)
      at java.net.URLClassLoader.access$400(URLClassLoader.java:119)
      at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:961)
      at java.security.AccessController.doPrivileged(AccessController.java:275)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:487)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:606)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:563)
      at java.lang.Class.forNameImpl(Native Method)
      at java.lang.Class.forName(Class.java:127)
      at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:57)
      at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
      at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:301)
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1497)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1041)
      at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:11)
      ... 3 more

hsqldb.jar has been downloaded from link
http://sourceforge.net/projects/hsqldb/files/alpha_beta/hsqldb_2_0_0_rc8/hsqldb-2.0.0-rc8.zip/download

Can i usse SQL instead of HSQL somehting like


<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property>



Please let me know how can i resolve this issue.
Any suggestions, ideas, resources, links, sample code highly appreciated. Thanks in advance.
OneOne.JPG
0
gudii9
Asked:
gudii9
  • 9
  • 8
2 Solutions
 
objectsCommented:
your driver was compiled for a later version of java than you are running. either run it with a later version of java (eg 1.6) or download a driver compiled for the version you are using
0
 
objectsCommented:
> Can i usse SQL instead of HSQL somehting like

yes you can use a different database, hsql is probably the easiest though
0
 
objectsCommented:
you would also be better off using the stable release

http://sourceforge.net/projects/hsqldb/files/hsqldb/hsqldb_1_8_1/
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
gudii9Author Commented:
Hi,

I right clicked on project and tried t to change the compiler version from 5.0 to 6.0 as in screenshot. But some reason it is disable some reason. Please let me know how to enable it to change the version. Also can i conenct to "mysql" database using HSQL driver. please advise
CompilerVersion.JPG
0
 
objectsCommented:
You have to check 'Enable project specific settings"
0
 
gudii9Author Commented:
Hi,

I was able to change the compiler version to 6.0 from 5.0 but still same error is coming as given below

The java class could not be loaded. java.lang.UnsupportedClassVersionError: (com/vaannila/student/Main) bad major version at offset=6


Please advise.
CompilerVersion1.JPG
0
 
gudii9Author Commented:
Hi,

When i try to run same example from eclipse on tomcat 6.0 I could by pass above error but getting new error


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException
      at com.vaannila.student.Main.main(Main.java:24)

I modified hibernate.cfg.xml  as
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/hibernatevaannila</property>
        <property name="hibernate.connection.username">gp</property>
        <property name="connection.password">gp</property>
        <property name="connection.pool_size">1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create</property>
        <mapping resource="com/vaannila/student/Student.hbm.xml"/>
        <mapping resource="com/vaannila/student/Address.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
to point to my local mysql 'hibernatevaannila' database.
Please advise.
0
 
objectsCommented:
looks like you are now compiling with java6 but are still running it with an earlier version.
you need to *run* it with java 6, check your run configuration settings.
0
 
gudii9Author Commented:
Hi,

How to run it with java 6  through RAD etc IDE?. I only see Java Compiler option. I do not see any 'runtime' kind of option for 6.0 to run. Please advise. Thanks in advane


CompilerVersion2.JPG
0
 
objectsCommented:
its in the runtime configuration that you use to start it (from the Run menu) as I mentioned above
0
 
gudii9Author Commented:
Hi,
I tried that way by clicking "RUN" and changing "JRE" configuration as "Webshere v6 JRE" still getting same error as

The java class could not be loaded. java.lang.UnsupportedClassVersionError: com/vaannila/student/Main (Unsupported major.minor version 49.0)


Please advise

0
 
objectsCommented:
check what version jre websphere is using
0
 
gudii9Author Commented:
Hi,
I found the location of JRE. But i was not sure how to check its version. Do i need to include just hsql.jar or entire zip file i downloaded
from
http://sourceforge.net/projects/hsqldb/files/alpha_beta/hsqldb_2_0_0_rc8/hsqldb-2.0.0-rc8.zip/download

 is needed?

I ran couple examples on mysql and oracle databases but not on hsql driver though. not sure how it is different?. Please advise
JRE1.JPG
0
 
objectsCommented:
you just need the jar, and you should use the stable version I posted earlier
the hql driver only works with hql databases
0
 
gudii9Author Commented:
Hi,

do i need to download the hql databas?. I only have mysql, oracle databases on my laptop local machine. Also here can i find the JRE version as in above screenshot? Please advise.
0
 
Sathish David Kumar NArchitectCommented:
Can u tell me ur pblm clearly ????
0
 
objectsCommented:
yes to use hql you need to have it available :)
You will need to change your database configuration to use a different database
0
 
gudii9Author Commented:
thank you very much
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now