1 Reply Latest reply on Jan 28, 2011 9:42 PM by ffang

    Hibernate with MySQL

    marim

      Hi,

       

      I am developing application which use Hibernate to connect to MySQL database. I've installed jpa-hibernate feature and this looks OK.

       

      Problem is with JDBC Driver. I have installed JDBC Driver for MySQL

       

      osgi:install -s mvn:mysql/mysql-connector-java

       

      206 Active        60 Sun Microsystems' JDBC Driver for MySQL (5.1.14)

       

      But when I try to invoke some operation on database I receive following exception about JDBC Driver class not found

       

      karaf@root> Exception in thread "Thread-36" java.lang.ExceptionInInitializerError

      at com.crazy.rodeo.checkers.CheckerGame.processRequest(CheckerGame.java:22)

      at com.crazy.rodeo.checkers.CheckerGameAsyncProcessor$1.run(CheckerGameAsyncProcessor.java:23)

      at java.lang.Thread.run(Thread.java:619)

      Caused by: org.hibernate.HibernateException: JDBC Driver class not found: org.gjt.mm.mysql.Driver

      at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:89)

      at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)

      at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)

      at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:425)

      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)

      at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)

      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)

      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)

      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

      at com.crazy.rodeo.hibernate.DAO.<clinit>(DAO.java:19)

      ... 3 more

      Caused by: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

      at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)

      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)

      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

      at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

      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.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:84)

      ... 12 more

        • 1. Re: Hibernate with MySQL
          ffang

          Hi,

           

          JDBC driver class not found actually is a frequently asked question, please see the similar discussion[1] and , this problem generally from a bundle(let's say it bundle A)  using  some code like classForName(jdbc_driver_classname) to init a jdbc driver class,  this is a big problem in OSGi world, as if BundleA not import package for jdbc_driver_classname, you'll see the problem. However BundleA actually can't know about package name for jdbc_driver_classname beforehand, as the jdbc_driver_classname generally is passed in through configuration during runtime, it can't be determined during build time, so you can't add correct package import when you generate bundle A.

           

          The general solution for this issue is that you create JDBC driver as a fragment bundle, and attach it to bundle A(bundle A is host bundle now), so that all resource from fragment bundle is available for the host bundle.

           

          http://fusesource.com/forums/thread.jspa?messageID=7745

          http://fusesource.com/forums/thread.jspa?messageID=8620

           

          Freeman