[hibernate-dev] ORM5 : Reusing the Configuration instance

Sanne Grinovero sanne at hibernate.org
Mon Mar 16 17:21:33 EDT 2015


On 16 March 2015 at 20:57, Hardy Ferentschik <hardy at hibernate.org> wrote:
> Hi,
>
> given that the SessionFactory gets closed after each test, I think it would
> only be fair to also rebuild the Configuration on each test set-up.
> What is the reason for keeping it around anyways? Do the tests run
> considerably slower when re-building the Configuration for each test?

I'm not sure, git is pointing to your name :-) See:
org.hibernate.search.test.TestResourceManager
It probably grew a bit of complexity over time and while I'm not sure
of what the original intention could be, I tend to agree with the
basic idea.

Even if we probably won't win much in terms of performance /
practicality and we were to agree to simplify this, the following
message is confusing:

java.util.ServiceConfigurationError:
org.hibernate.service.spi.ServiceContributor: Provider
org.hibernate.search.hcore.impl.SearchFactoryServiceContributor not
found
     at java.util.ServiceLoader.fail(ServiceLoader.java:231)
     at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
     at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
     at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:339)
     at org.hibernate.boot.registry.StandardServiceRegistryBuilder.applyServiceContributors(StandardServiceRegistryBuilder.java:319)
     at org.hibernate.boot.registry.StandardServiceRegistryBuilder.build(StandardServiceRegistryBuilder.java:296)
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:740)

As an Hibernate ORM user I would expect the Configuration to be
reusable, and probably immutable as well.

Sanne


>
> --Hardy
>
> On Sun, Mar 15, 2015 at 11:36:00PM +0000, Sanne Grinovero wrote:
>> Hi all,
>> I'm trying to get an experimental branch of Hibernate Search to work
>> with the latest snapshot of Hibernate ORM 5.
>>
>> After a bit of refactoring of our integration SPIs I thought it was
>> ready for some testing, but came to some surprising errors from the
>> ServiceLoader not finding the implementations from Hibernate Search -
>> although it would find the service definition of it.
>>
>> After a bit more investigating, it turns out that the Integrator works
>> fine for each first test of our testsuite; it turns out that the
>> ClassLoaderService is referenced by the Configuration instance, and
>> this specific service nulls out all references to classloaders on
>> shutdown of the SessionFactory (which happens at the end of each of
>> our tests).
>>
>> When the second test runs, it's reusing the same instance of ORM's
>> Configuration and so the ClassLoaderService gets reused and not
>> properly re-initialized, so it's not able to load any class.
>>
>> So I'm wondering now if we should stop re-using the Configuration
>> instance in Search across tests, or if the ClassLoaderService in ORM
>> should be re-initialized on restart?
>> (this re-using business is mostly a convenience for how the Search
>> testsuite works but not strictly necessary)
>>
>> If we should stop reusing the Configuration instances, then I'd like
>> to add a validation in ORM as the errormessage thrown from the
>> java.util.ServiceConfigurationError is confusing.
>>
>> Thanks,
>> Sanne
>> _______________________________________________
>> 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