title: PostgreSQL connector on OSGi
body: <p>I'm working on an OSGi application using Karaf. </p>
  
  <p>This application connects to a postgresql database using Hibernate 4.3.</p>
  
  <p>My application works when I use the hibernate default connection pool but JBoss advices not to use it on a prod system. So I'm trying to use a c3p0 connection pool.</p>
  
  <p>I use the following bundles:</p>
  
  <pre><code>&lt;bundle wrap="yes"&gt;hibernate-jpa-2.1-api-1.0.0.Final&lt;/bundle&gt;
  &lt;bundle wrap="no"&gt;hibernate-core-4.3.7.Final&lt;/bundle&gt;       
  &lt;bundle wrap="no"&gt;hibernate-entitymanager-4.3.7.Final&lt;/bundle&gt;
  &lt;bundle wrap="no"&gt;hibernate-c3p0-4.3.7.Final&lt;/bundle&gt;
  &lt;bundle wrap="no"&gt;hibernate-envers-4.3.7.Final&lt;/bundle&gt;
  &lt;bundle wrap="no"&gt;hibernate-osgi-4.3.7.Final&lt;/bundle&gt;
  </code></pre>
  
  <p>In order to use c3p0, I also add the requiered third party library: </p>
  
  <pre><code>&lt;bundle wrap="yes"&gt;c3p0-0.9.2.1&lt;/bundle&gt;
  </code></pre>
  
  <p><code>wrap</code>option is set to <code>"yes"</code> as it's a simple jar file.</p>
  
  <p>All those bundles are correctly loaded by karaf.</p>
  
  <p>Now my problem is to add the PostgreSQL driver: I have <code>postgresql-9.3-1102.jdbc41.jar</code>, which is not a bundle (no manifest.mf file). </p>
  
  <p>I tried to:</p>
  
  <ul>
  <li>add it to the classpath</li>
  <li>wrap it using <code>&lt;bundle wrap="no"&gt;postgresql-9.3-1102.jdbc41.jar&lt;/bundle&gt;</code> in <code>bundles.xml</code></li>
  <li>wrap it throught eclipse using <a href="http://cq-ops.tumblr.com/post/21893960212/how-to-turn-a-jdbc-driver-jar-into-an-osgi-bundle" rel="nofollow">this tutorial</a></li>
  <li>make it into a fragment, hosted by my dao-layer bundle</li>
  </ul>
  
  <p>But nothing works. Each times c3p0 start the connexion pool and when it comes to find the right driver, it fails with this message:</p>
  
  <pre><code>java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:278)[:1.7.0_67]
      at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:240)[98:wrap_file_D_container_karaf_bundles_c3p0-0.9.2.1.jar:0]
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)[98:wrap_file_D_trunk_container_karaf_bundles_c3p0-0.9.2.1.jar:0]
  </code></pre>
  
  <p>Looking for this kind of problem, I found there are 2 reasons this may append: </p>
  
  <ul>
  <li>the hibernate.connection.url may be wrong. But that's not my case. I checked it multiple times.</li>
  <li>The postgresql driver is not loaded </li>
  </ul>
  
  <p>Is there any magical trick to use c3p0 with hibernate on a OSGi environment?</p>