3

I'm trying to use Hibernate-Search in one of my JavaEE projects and seem to run into the exact same problem as described by Rallenaldo:

My Maven-project is using

  • Java JDK 1.8.0_73
  • Hibernate 5.0.6.Final
  • Hibernate-Search 5.5.2.Final (which uses Lucene 5.3.1)

and try to deploy on a Glassfish 4.1.1 application server (with just minimal changes to the standard configuration).

When deploying my application the deployment process ends in the following ClassCastException, when Lucene tries to load codecs from the package lucene-backward-codecs (version 5.3.1):

java.lang.ClassCastException: class org.apache.lucene.codecs.lucene40.Lucene40PostingsFormat
at java.lang.Class.asSubclass(Class.java:3404)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:141)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:65)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:47)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.PostingsFormat$Holder.<clinit>(PostingsFormat.java:49)
at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
at org.apache.lucene.codecs.lucene40.Lucene40Codec.<init>(Lucene40Codec.java:115)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:67)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:45)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.Codec$Holder.<clinit>(Codec.java:47)
at org.apache.lucene.codecs.Codec.forName(Codec.java:113)
at org.apache.lucene.index.SegmentInfos.readCodec(SegmentInfos.java:469)
...

As has been elsewhere suggested, I have already verified that on my computer there is no other version of Lucene nor Hibernate-Search.

If I exclude the lucene-backward-codecs dependecy from the Maven-project, I get a similar ClassCastException at the exact same location in the Lucene-code:

java.lang.ClassCastException: class org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat
at java.lang.Class.asSubclass(Class.java:3404)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:141)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:65)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:47)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.PostingsFormat$Holder.<clinit>(PostingsFormat.java:49)
at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
at org.apache.lucene.codecs.lucene53.Lucene53Codec.<init>(Lucene53Codec.java:160)
at org.apache.lucene.codecs.lucene53.Lucene53Codec.<init>(Lucene53Codec.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...

I was not able to find a solution to this problem. And I am aware that Rallenaldo's question is actally also still open. Does someone know what causes this problem? Is this a Glassfish 4.1.1 problem?


Edit: I want to add the following observation to my original post: part of my project generates an standalone application packed as a self executable jar-file with the identical hibernate and lucene related dependencies, where I also use an entity manager with essentially the same configuration for the presistence context. In this case I do not have the above problem with hibernate-search. It starts without any problem and I can see it generate the expected index files. Here are the relevant lines from the persistence.xml:

<persistence-unit name="puName" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <properties>
        ...
        <property name="hibernate.search.default.directory_provider" value="filesystem"/>
        <property name="hibernate.search.default.indexBase" value="/path/to/lucene/indexes"/>
        ...
    </properties>
</persistence-unit>
Community
  • 1
  • 1

1 Answers1

0

Ok. Here is better answer. The solution (workaround) for us was to put lucene-analyzers-common-5.3.1.jar and lucene-core-5.3.1.jar directly into domain lib folder. After debugging I have found that class Lucene40PostingsFormat is being loaded by two classloaders and then instantiated from first classloader as a subclass of another (it gives class cast exception). I assume there is one unnecessary loading but I do not know why and how to change it with configuration only.

kalosh
  • 63
  • 1
  • 5
  • Thanks for the information! :-) It looks promising. However right now I'm on holiday. I have to look into it again when I am back and have a bit time. I will post my findings as soon as I get to it. – Martin Fluch Aug 27 '16 at 09:42
  • @kalosh, can you elaborate, I have not much idea of class loaders, I am facing the same exception – sumanth232 Apr 01 '17 at 19:14
  • @krishna222 Just put mentioned lucene libs to /yourdomainFolder/lib – kalosh Apr 19 '17 at 10:41