You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by ychawla <pr...@gmail.com> on 2011/08/11 18:04:49 UTC

Using c3p0 and hibernate in OSGi bundle in ServiceMix

Hello All,
I have been trying to set up a Camel Route with ServiceMix and hibernate and
been running into some issues.  I am going to document them here along with
some questions.

ServiceMix 4.3.0 doesn't ship with jpa-hibernate features, however fuse
does.  To get hibernate working inside ServiceMix 4.3.0, I copied over the
features descriptor and the JDBC driver.  Are there plans to add this
feature to the open source version:

    <feature name="jpa-hibernate" version="4.3.0">
        <bundle
dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.java-persistence-api-1.1.1/1.8.0</bundle>
        <bundle
dependency="true">mvn:org.springframework/spring-jdbc/3.0.5.RELEASE</bundle>
        <bundle
dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_3</bundle>
        <bundle
dependency="true">mvn:org.antlr/com.springsource.antlr/2.7.7</bundle>
        <bundle
dependency="true">mvn:org.objectweb.asm/com.springsource.org.objectweb.asm/1.5.3</bundle>
        <bundle
dependency="true">mvn:net.sourceforge.cglib/com.springsource.net.sf.cglib/2.2.0</bundle>
        <bundle
dependency="true">mvn:org.jboss.javassist/com.springsource.javassist/3.9.0.GA</bundle>
       
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga</bundle>
       
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations/3.4.0.GA</bundle>
       
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.ejb/3.4.0.GA</bundle>
       
<bundle>mvn:org.hibernate/com.springsource.org.hibernate/3.3.2.GA</bundle>
        <bundle>mvn:org.springframework/spring-orm/3.0.5.RELEASE</bundle>
        
       
<bundle>mvn:org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi</bundle>
        <bundle>mvn:org.springframework/spring-aop/3.0.5.RELEASE</bundle>
    </feature>
    
    <feature name="jdbc-drivers">
       
<bundle>mvn:com.mysql.jdbc/com.springsource.com.mysql.jdbc/5.1.6</bundle>
    </feature>

I was also getting some strange errors about: SpringProxy is not visible
from class loader.  To solve that, I added these import packages (also
showing the hibernate and driver imports):

org.springframework.aop,
org.springframework.aop.framework,
org.aopalliance.aop,
org.hibernate.jdbc,
com.mysql.jdbc,
*

Once I did that, the application started and was throwing errors :
Could not load driverClass com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

The JDBC drivers is imported and installed in ServiceMix.  This seems to be
due to how c3p0 classes get loaded.  According to Costin Leau:  "For things
to work nicely inside OSGi you need to use the proper class loader.
Class.forName() w/o a classloader doesn't do that"  Here's the link:

http://forum.springsource.org/showthread.php?59588-CNFE-when-loading-mysql-jdbc-driver&s=822a095d05cd327b315cc50a7eec4587

Has anyone been able to set up a c3p0 connection pool in ServiceMix?  I went
ahead and switched to dbcp and that is working.  It looks like the next
release of ServiceMix will have a dbcp feature included.

This next piece is probably a little off topic, but I will include it
anyway:
Up next I found a bug in the version of Hibernate that is OSGi packaged by
Spring Source.  The issue is fixed in 3.5.4, however the OSGi package has
3.3.2.  The bug didn't allow identify fields to be defined as BigInteger:

https://hibernate.onjira.com/browse/HHH-4905

This can be patched by updating a single class:
org/hibernate/id/IdentifierGeneratorFactory.java.  I made this update in my
project and when I ran my camel route in Eclipse with camel:run, the patched
code was used.  However, when I deploy to ServiceMix, it didn't use the
patched code.  Is there anyway to explicitly tell ServiceMix which class to
use?  

To solve this issue, I updated my existing code base to work with Hibernate
3.3.2.  It would be nice if Hibernate distributed OSGi bundles for the
latest releases of their code.

Thanks,
Yogesh
 

--
View this message in context: http://servicemix.396122.n5.nabble.com/Using-c3p0-and-hibernate-in-OSGi-bundle-in-ServiceMix-tp4690037p4690037.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Using c3p0 and hibernate in OSGi bundle in ServiceMix

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

My comment inline
On 2011-8-12, at 上午12:04, ychawla wrote:

> Hello All,
> I have been trying to set up a Camel Route with ServiceMix and  
> hibernate and
> been running into some issues.  I am going to document them here  
> along with
> some questions.
>
> ServiceMix 4.3.0 doesn't ship with jpa-hibernate features, however  
> fuse
> does.  To get hibernate working inside ServiceMix 4.3.0, I copied  
> over the
> features descriptor and the JDBC driver.  Are there plans to add this
> feature to the open source version:
No, we can't do it, because some bundle from jpa-hibernate features  
doesn't use Apache compatible license
>
>    <feature name="jpa-hibernate" version="4.3.0">
>        <bundle
> dependency="true">mvn:org.apache.servicemix.specs/ 
> org.apache.servicemix.specs.java-persistence-api-1.1.1/1.8.0</bundle>
>        <bundle
> dependency="true">mvn:org.springframework/spring-jdbc/3.0.5.RELEASE</ 
> bundle>
>        <bundle
> dependency="true">mvn:org.apache.servicemix.bundles/ 
> org.apache.servicemix.bundles.dom4j/1.6.1_3</bundle>
>        <bundle
> dependency="true">mvn:org.antlr/com.springsource.antlr/2.7.7</bundle>
>        <bundle
> dependency="true">mvn:org.objectweb.asm/ 
> com.springsource.org.objectweb.asm/1.5.3</bundle>
>        <bundle
> dependency="true">mvn:net.sourceforge.cglib/ 
> com.springsource.net.sf.cglib/2.2.0</bundle>
>        <bundle
> dependency="true">mvn:org.jboss.javassist/com.springsource.javassist/ 
> 3.9.0.GA</bundle>
>
> <bundle>mvn:org.hibernate/ 
> com.springsource.org.hibernate.annotations.common/3.3.0.ga</bundle>
>
> <bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations/ 
> 3.4.0.GA</bundle>
>
> <bundle>mvn:org.hibernate/com.springsource.org.hibernate.ejb/ 
> 3.4.0.GA</bundle>
>
> <bundle>mvn:org.hibernate/com.springsource.org.hibernate/3.3.2.GA</ 
> bundle>
>        <bundle>mvn:org.springframework/spring-orm/3.0.5.RELEASE</ 
> bundle>
>
>
> <bundle>mvn:org.apache.commons/ 
> com.springsource.org.apache.commons.dbcp/1.2.2.osgi</bundle>
>        <bundle>mvn:org.springframework/spring-aop/3.0.5.RELEASE</ 
> bundle>
>    </feature>
>
>    <feature name="jdbc-drivers">
>
> <bundle>mvn:com.mysql.jdbc/com.springsource.com.mysql.jdbc/5.1.6</ 
> bundle>
>    </feature>
>
> I was also getting some strange errors about: SpringProxy is not  
> visible
> from class loader.  To solve that, I added these import packages (also
> showing the hibernate and driver imports):
>
> org.springframework.aop,
> org.springframework.aop.framework,
> org.aopalliance.aop,
> org.hibernate.jdbc,
> com.mysql.jdbc,
> *
>
> Once I did that, the application started and was throwing errors :
> Could not load driverClass com.mysql.jdbc.Driver
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
>
> The JDBC drivers is imported and installed in ServiceMix.  This  
> seems to be
> due to how c3p0 classes get loaded.  According to Costin Leau:  "For  
> things
> to work nicely inside OSGi you need to use the proper class loader.
> Class.forName() w/o a classloader doesn't do that"  Here's the link:
>
> http://forum.springsource.org/showthread.php?59588-CNFE-when-loading-mysql-jdbc-driver&s=822a095d05cd327b315cc50a7eec4587
>
> Has anyone been able to set up a c3p0 connection pool in  
> ServiceMix?  I went
> ahead and switched to dbcp and that is working.  It looks like the  
> next
> release of ServiceMix will have a dbcp feature included.
>
I think you hit a common issue when load jdbc drivers in OSGi  
container, you may need take a look at similar discussion here[1]
[1]http://fusesource.com/forums/thread.jspa?messageID=9780&#9780
> This next piece is probably a little off topic, but I will include it
> anyway:
> Up next I found a bug in the version of Hibernate that is OSGi  
> packaged by
> Spring Source.  The issue is fixed in 3.5.4, however the OSGi  
> package has
> 3.3.2.  The bug didn't allow identify fields to be defined as  
> BigInteger:
>
> https://hibernate.onjira.com/browse/HHH-4905
>
> This can be patched by updating a single class:
> org/hibernate/id/IdentifierGeneratorFactory.java.  I made this  
> update in my
> project and when I ran my camel route in Eclipse with camel:run, the  
> patched
> code was used.  However, when I deploy to ServiceMix, it didn't use  
> the
> patched code.  Is there anyway to explicitly tell ServiceMix which  
> class to
> use?
>
> To solve this issue, I updated my existing code base to work with  
> Hibernate
> 3.3.2.  It would be nice if Hibernate distributed OSGi bundles for the
> latest releases of their code.
>
I think you need create a new hibernate bundle which use 3.5.4  
hibernate release.
Per the license issue I mentioned before, we can't do it here in  
Servicemix.

Freeman
> Thanks,
> Yogesh
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Using-c3p0-and-hibernate-in-OSGi-bundle-in-ServiceMix-tp4690037p4690037.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com