Hibernate Search 6.2.0.Alpha2 Index Problem

401 Views Asked by At

Upgraded from Hibernate Search 6.2.0.Alpha1 to 6.2.0.Alpha2

No other changes and we are now getting the following runtime error when the application attempts to create the initial indexes.

Caused by: org.hibernate.search.util.common.SearchException: HSEARCH900013: Exception 
while accessing Jandex index for 
'jar:file:/home/ash/Dev/pins5/pins5/integration/integration-batch- 
service/build/libs/integration-batch-service.jar!/BOOT-INF/lib/security-persistence  
-plain.jar!/': HSEARCH900014: Exception while building Jandex index for 
'jar:file:/home/ash/Dev/pins5/pins5/integration/integration-batch- 
service/build/libs/integration-batch-service.jar!/BOOT-INF/lib/security-persistence- 
plain.jar!/': HSEARCH900016: Cannot open filesystem for code source at 
'jar:file:/home/ash/Dev/pins5/pins5/integration/integration-batch- 
service/build/libs/integration-batch-service.jar!/BOOT-INF/lib/security-persistence- 
plain.jar!/': HSEARCH900018: Cannot open a ZIP filesystem for code source at 
'jar:file:/home/ash/Dev/pins5/pins5/integration/integration-batch- 
service/build/libs/integration-batch-service.jar!/BOOT-INF/lib/security-persistence- 
plain.jar!/', because the URI points to content inside a nested JAR.

The only changes we have made have been updating our dependencies from

 'org.hibernate.search:hibernate-search-mapper-orm:6.2.0.Alpha1'
 'org.hibernate.search:hibernate-search-backend-elasticsearch:6.2.0.Alpha1'

to

 'org.hibernate.search:hibernate-search-mapper-orm:6.2.0.Alpha2'
 'org.hibernate.search:hibernate-search-backend-elasticsearch:6.2.0.Alpha2'

Looking at the release notes I see the following

Due to switching from new URL(..) to new URI(..) in the Hibernate Search internals > indexing behaviour of URL properties might change. In particular malformed URLs won’t be accepted anymore and would result in a runtime exception.

The hibernate search properties that we set in our yaml are as follows but none of these were changed as part of the upgrade

search:
      backend:
             type: elasticsearch
             uris: localhost:9200
             minimal_required_status: yellow
             analysis:
                     configurer: com.saadian.pins.persistence.base.elastic.config.analyzer.CustomAnalyzerProvider
             enabled: true
             schema_management:
                    strategy: create-or-update
             automatic_indexing:
                    enabled: true
                    synchronization:
                        strategy: async

Other information the application uses Spring Boot 2.7

Looking at the changes from Alpha1 to Alpha2 the only thing I can see that might possibly have introduced this is the fix for https://hibernate.atlassian.net/browse/HSEARCH-4724

I assume I can probably do something like outlined in Hibernate Search 6 @ProjectionConstructor not working but would be great if anyone has any guidance on what might be required.

Updating to Spring Boot 2.7.8 makes no difference.

Any help / ideas would be greatly appreciated

3

There are 3 best solutions below

2
Paulo Consoni On

I'm in the same scenario. Reasearching in Hibernate search's code, I found this code:

private void tryInitJarFileSystem(URI jarUri) throws IOException {
    try {
        nonDefaultFileSystem = FileSystems.newFileSystem( jarUri, Collections.emptyMap() );
        classesPathInFileSystem = nonDefaultFileSystem.getRootDirectories().iterator().next();
        // The ZipFileSystemProvider ignores the "path inside the JAR",
        // so we need to take care of that ourselves.
        String nestedPath = extractedJarNestedPath( jarUri );
        if ( nestedPath != null ) {
            Path nestedPathInFileSystem = classesPathInFileSystem.resolve( nestedPath );
            if ( Files.isRegularFile( nestedPathInFileSystem ) ) {
                // TODO HSEARCH-4744 support reading the content of nested JARs
                throw log.cannotOpenNestedJar( jarUri );
            }
            classesPathInFileSystem = nestedPathInFileSystem;
        }
    }
    catch (RuntimeException | IOException e) {
        new SuppressingCloser( e )
                .push( nonDefaultFileSystem );
        nonDefaultFileSystem = null;
        classesPathInFileSystem = null;
        throw e;
    }
}

// TODO HSEARCH-4744 support reading the content of nested JARs

So There is no support for nested JARs in Hibernate 6.2 yet.

In my case, I downgraded to 6.1.8Final.

0
Ashley Callaghan On

The following fixed our problem

In your applicationy.yaml or equivalent add the following property

hibernate:
   search:
     mapping:
      configurer: com.saadian.pins.persistence.base.elastic.config.mapper.HibernateSearchMappingConfigurer

Then we added the following Java class

@Component
public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {

@Override
public void configure(HibernateOrmMappingConfigurationContext context) {

    context.annotationMapping().buildMissingDiscoveredJandexIndexes(false);
    try {
        URI uri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
        String schemeSpecificPart = uri.getSchemeSpecificPart();
        Optional<Index> optionalIndex = JandexUtils.readIndex(Paths.get(schemeSpecificPart.substring(schemeSpecificPart.indexOf(":") + 1, schemeSpecificPart.indexOf("!"))).toUri().toURL());
        optionalIndex.ifPresent(index -> context.annotationMapping().add(index));

    } catch (URISyntaxException | MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

}

This solved the problem for us at least

0
Abdourahmane FALL On

Use solve by doing like this :

  • properties yml file : hibernate.mapping.process_annotations: false hibernate.mapping.configurer: com.fallphenix.persistance.common.HibernateSearchMappingConfigurer

  • Implementation

import org.hibernate.search.mapper.orm.mapping.HibernateOrmMappingConfigurationContext;
import org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer;
import org.springframework.stereotype.Component;

public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {

    @Override
    public void configure(HibernateOrmMappingConfigurationContext context) {
        context.annotationMapping()
                .add(Object1Entity.class)
                .add(Object2Entity.class)
                .add(ObjectNEntity.class)
                .discoverAnnotationsFromReferencedTypes(true)
                .discoverAnnotatedTypesFromRootMappingAnnotations(true);
    }
}

Verions bellow :

<java.version>17</java.version>
<spring.boot.version>3.1.1</spring.boot.version>
 <hibernate.version>6.2.6.Final</hibernate.version>
<hibernate.search.version>6.2.0.Final</hibernate.search.version>