[hibernate-dev] Solution for failing Isolated query cache tests in Hibernate trunk
Galder Zamarreno
galder at jboss.org
Wed Jan 13 13:02:21 EST 2010
On 01/13/2010 05:31 PM, Galder Zamarreno wrote:
> Hi all,
>
> In Hibernate trunk, the following tests are failing:
>
> In JBC 2LC provider:
> MVCCIsolatedClassLoaderTest.testClassLoaderHandlingNamedQueryRegion
> MVCCIsolatedClassLoaderTest.testClassLoaderHandlingStandardQueryCache
>
> In Infinispan 2LC provider:
> IsolatedClassLoaderTest.testClassLoaderHandlingNamedQueryRegion
> IsolatedClassLoaderTest.testClassLoaderHandlingStandardQueryCache
>
> They're failing because AccountHolder is being loaded with the system
> classloader rather than the SelectedClassnameClassLoader.
>
> The reason for this is that as a result of
> http://opensource.atlassian.com/projects/hibernate/browse/HHH-2990,
> SerializationHelper.CustomObjectInputStream now takes the classloader in
> the constructor. And during the test, SerializableType.fromBytes passes
> null as classloader to this constructor. The null comes from
> getReturnedClass().getClassLoader() below, which has been added as a
> result of 2990.
>
> private Object fromBytes(byte[] bytes) throws SerializationException {
> return SerializationHelper.deserialize( bytes,
> getReturnedClass().getClassLoader() );
> }
>
> Now, shouldn't we use Thread.currentThread().getContextClassLoader()
> instead of getReturnedClass().getClassLoader()? Previously, that's what
> would have happened. I dunno why getReturnedClass().getClassLoader() was
> added though.
>
> I've just tested using Thread.currentThread().getContextClassLoader()
> change and the tests pass now. Steve?
For completion, getReturnedClass().getClassLoader() will always return
null because SerializableType is initialised with java.io.Serializable
as returned class, and it's classloader returns null (quite likely cos
it's a system class?).
So, getReturnedClass().getClassLoader() is not the answer here.
Steve, from a chat earlier you indicated that you're not happy passing
Thread.currentThread().getContextClassLoader() but I don't understand
what issue do you have with this.
Also, I'm not an expect on
Thread.currentThread().getContextClassLoader().loadClass() vs
Class.forName(String,boolean,Thread.currentThread().getContextClassLoader())
to be able to say whether either would work fine in an AS environment.
The test pass when you use the latter.
Finally, it might be worth understanding what, apart from query cache,
is Hibernate's SerializationHelper used for. If it's only for caching,
you could maybe delegate serialization work to the cache providers?
>
> Cheers,
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list