I've been struggling to get our code that uses Hibernate to work within Karaf
4.1 today.
I have created a simple test case, which is on github:
https://github.com/tomq42/karaf-tests-hibernate. There are a variety of
branches, each with a different combination of hibernate and karaf. The
branches karaf_4.0.9 and hibernate_5.3.4_karaf_4.1.1 are the most interesting.
My test is to have a bundle with an activator, where the start method just does:
javax.validation.Validation
.byProvider(HibernateValidator.class)
.providerResolver(new MyProviderResolver())
.configure()
.buildValidatorFactory()
.getValidator();
I write the java with bndtools in Eclipse. I then run the gradle script
provided by bndtools to publish the resulting bundle to my local maven
repository. I then run maven to build a feature containing the bundle, and then
use the karaf-assembly packaging to product a karaf distribution, including the
karaf "enterprise" feature repository, and hence its "hibernate-validator"
feature. I then run the distribution, and it either says "great, created a
validator", or prints a nasty stack trace.
If I try this with karaf 4.1.1, I can't get it to work. It fails with
javax.validation.ValidationException: HV000183: Unable to initialize
'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the
classpath
...
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl
not found by org.hibernate.validator
The thing is that I try with Karaf 4.0.9, and I *can* get it to work. Same
code, just compiled against different versions of hibernate, so that the
requirements match the version of karaf. In both cases, I have configured
Eclipse/bndtools to use the same version of hibernate as that version of Karaf
ships with.
Karaf 4.0 series seems to use hibernate 5.0.3, Karaf 4.1 seems to use hibernate
5.3.4.
>From within eclipse I can run OSGi using bndtools. If I compile and run
>against Hibernate 5.0, and ensure that the glassfish.javax.el bundle is
>available at runtime, I can successfully create a validator. I can then build
>the same bundle and build my Karaf 4.0 based distribution, and the result
>runs. I can use hibernate 5.2 as well, and that works within bndtools (I'm not
>sure I would know how to make karaf use a later version of hibernate than the
>one it ships with).
If I build and run against hibernate 5.3 within bndtools, I get the error
(java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl), and I get
the same if I then build the java and build my karaf 4.1 based distribution.
Note that in both cases I have the glassfish.javax.el available, so the
com.sun.el classes should be available.
For a while I was convinced that it was a problem with boot class delegation,
since com.sun.* is in the org.osgi.framework.bootdelegation setting in the
config.properties file. I wondered whether because of that boot class
delegation, it wouldn't attempt to load the classes out of the bundle, and
instead try to load them from the boot classloader. However the same is true in
Karaf 4.0.9, and it works fine there. So I think that was a red herring.
So something seems to changed within hibernate to render it incompatible with
Karaf 4.1?
So I'm out of ideas. The fact that it works in 4.0.9 suggest that fundamentally
I'm not doing anything wrong, and that something has changed in hibernate to
cause this to now fail.
I found an old thread on this list on which Christian had posted a link to some
test cases for Hibernate, here:
https://github.com/hibernate/hibernate-validator/blob/master/osgi/integrationtest/src/test/java/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java.
I have experimented with using context class loaders, as per the test case, in
the hope that this might fix it, but it doesn't seem to.
Can anyone confirm whether hibernate works on 4.1.1, and if so, what I'm doing
wrong? I'm hoping I've just missed something obvious, but I've looked at this
every which way I can and can't find anything.
Thanks (again).