-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unable to use Derby with Hibernate
PostPosted: Sun Jul 15, 2012 10:17 pm 
Newbie

Joined: Sun Jul 15, 2012 7:57 am
Posts: 5
Hi everyone,

I am desperately trying to make hibernate work with Apache Derby plugin in my eclipse RCP project.

When I run the application i get an error saying unable to instantiate driver class file. The details are listed below.

Any help is much appreciated.

Here is my config file
Code:
<?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 name="mySessionFactory">
  <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
  <property name="hibernate.connection.url">jdbc:derby:/Users/Shashank/Desktop/rubrics/Rubrics/database/rubricsData</property>
  <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
  <property name="hibernate.format_sql">false</property>
</session-factory>
</hibernate-configuration>


I have derby databases properly setup. I am also able to get access to the database using Hibernate console configuration in the Eclipse IDE.

But when I run the application I get the following errors:

Quote:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
JDBC Driver class not found: org.apache.derby.jdbc.EmbeddedDriver
!SESSION 2012-07-16 12:07:17.589 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_33
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments: -product Rubrics.product
Command-line arguments: -product Rubrics.product -data /Users/Shashank/Desktop/rubrics/../runtime-pc.product -dev file:/Users/Shashank/Desktop/rubrics/.metadata/.plugins/org.eclipse.pde.core/pc.product/dev.properties -os macosx -ws cocoa -arch x86_64 -consoleLog

!ENTRY org.eclipse.osgi 4 0 2012-07-16 12:07:19.075
!MESSAGE Application error
!STACK 1
java.lang.ExceptionInInitializerError
at rubrics.datatools.HibernateUtil.getSessionFactory(HibernateUtil.java:25)
at rubrics.RubricsApplication.start(RubricsApplication.java:44)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found: org.apache.derby.jdbc.EmbeddedDriver
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:123)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:438)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at rubrics.datatools.HibernateUtil.getSessionFactory(HibernateUtil.java:19)
... 14 more
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:118)
... 23 more
An error has occurred. See the log file
/Users/Shashank/Desktop/runtime-pc.product/.metadata/.log.



Here is the code where the exceptions are generated:

Code:
package rubrics.datatools;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import rubrics.RubricsPlugin;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
   private static SessionFactory sessionFactory = null;
   
   
   public static SessionFactory getSessionFactory()
   {
      if(sessionFactory == null)
      {
         try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            sessionFactory = new AnnotationConfiguration().configure(RubricsPlugin.hibernateCfgPath).buildSessionFactory();
         
         }
         catch (Throwable ex)
         {
            System.out.println(ex.getMessage());
            throw new ExceptionInInitializerError(ex);
         }
      }
      return sessionFactory;
   }
   
   

}


Top
 Profile  
 
 Post subject: Re: Unable to use Derby with Hibernate
PostPosted: Mon Jul 16, 2012 8:56 am 
Newbie

Joined: Thu Jul 12, 2012 5:22 pm
Posts: 4
I just got my Derby to (almost) work. I ended up using Derby client/server instead of embedded. May be embedded should work also but you can try this to see if it's caused by 'embedded'. You will need to swap out some of the particulars with ones that apply to your install and application. Also you would need to start up the Derby server before running this.

Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>

<!-- Database connection settings -->
    <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="connection.url">jdbc:derby://localhost:1527/imagedb</property>
    <property name="connection.username">user1</property>
    <property name="connection.password">user1</property>       
       
    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.DerbyDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

    <mapping resource="hibernate.hbm.xml"/>
       
  </session-factory>
</hibernate-configuration>


I also added this simple log4j.properties file in the src directory.

Code:
log4j.rootLogger=WARN, Console
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%-r [%t] %-5p %c %x - %m%n
log4j.appender.Console=org.apache.log4j.ConsoleAppender


The other thing I ran into was a number of .jar files that were needed at run-time but not needed at compile time. I had to download these, put them in a lib directory and then add them to my project path.

Hope this gets you one step further.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.