Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> Can i usse SQL instead of HSQL somehting like

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

http://sourceforge.net/projects/hsqldb/files/hsqldb/hsqldb_1_8_1/
Avatar of gudii9

ASKER

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
You have to check 'Enable project specific settings"
Avatar of gudii9

ASKER

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
Avatar of gudii9

ASKER

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.
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.
Avatar of gudii9

ASKER

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
its in the runtime configuration that you use to start it (from the Run menu) as I mentioned above
Avatar of gudii9

ASKER

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

check what version jre websphere is using
Avatar of gudii9

ASKER

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
you just need the jar, and you should use the stable version I posted earlier
the hql driver only works with hql databases
Avatar of gudii9

ASKER

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.
Can u tell me ur pblm clearly ????
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

thank you very much