Not detecting @ProjectionConstructor

ERROR:
15-11-2022 19:11:28.382 || ERROR || com.sixdee.rom.core.api.ProductOrderApiDelegate_v2 || 1724 || Other info Log || null || FF94E1DE53EE830BB36E10273DBF1D38 || NA || NA || Error occured:
org.hibernate.search.util.common.SearchException: HSEARCH700112: Invalid object class for projection: com.sixdee.rom.core.projections.ProductOrderProjection. Make sure that this class is mapped correctly, either through annotations (@ProjectionConstructor) or programmatic mapping. If it is, make sure the class is included in a Jandex index made available to Hibernate Search.
at org.hibernate.search.mapper.pojo.search.definition.impl.PojoSearchQueryElementRegistry.composite(PojoSearchQueryElementRegistry.java:32) ~[hibernate-search-mapper-pojo-base-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.engine.search.projection.dsl.impl.CompositeProjectionInnerStepImpl.as(CompositeProjectionInnerStepImpl.java:50) ~[hibernate-search-engine-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.backend.elasticsearch.search.query.dsl.impl.ElasticsearchSearchQuerySelectStepImpl.select(ElasticsearchSearchQuerySelectStepImpl.java:67) ~[hibernate-search-backend-elasticsearch-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]

After facing above issue referred below 2 links

Referred links:

Now getting error as:

15-11-2022 19:39:05.721 || INFO || org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator || 52 || || || || || || HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
15-11-2022 19:39:05.838 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 24 || || || || || || class uri: file:/D:/SMARTFREN/Smart-philli/rom-core-svc/target/classes/
2022-11-15 19:39:05,871 main ERROR Unable to delete file D:\usr\local\tomcat\logs\SpringBoot2App\rom-CoreAapplicationLogs.log: java.nio.file.FileSystemException D:\usr\local\tomcat\logs\SpringBoot2App\rom-CoreAapplicationLogs.log: The process cannot access the file because it is being used by another process
15-11-2022 19:39:05.839 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 26 || || || || || || class uri ssp: /D:/SMARTFREN/Smart-philli/rom-core-svc/target/classes/

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
15-11-2022 19:39:06.884 || ERROR || org.springframework.boot.SpringApplication || 843 || || || || || || Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.StringIndexOutOfBoundsException: begin 3, end -1, length 55
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.5.jar:2.5.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.5.jar:2.5.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.5.jar:2.5.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.5.jar:2.5.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.5.jar:2.5.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.5.jar:2.5.5]
at com.sixdee.rom.core.RomCoreSmartphilApplication.main(RomCoreSmartphilApplication.java:39) [classes/:?]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.StringIndexOutOfBoundsException: begin 3, end -1, length 55
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421) ~[spring-orm-5.3.10.jar:5.3.10]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.10.jar:5.3.10]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.10.jar:5.3.10]
… 16 more
Caused by: java.lang.StringIndexOutOfBoundsException: begin 3, end -1, length 55

CODE:

Property file – spring.jpa.properties.hibernate.search.mapping.configurer=searchMappingConfigurer

@Component(“searchMappingConfigurer”)
public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {

Logger logger = LoggerFactory.getLogger(HibernateSearchMappingConfigurer.class);

@Override
public void configure(HibernateOrmMappingConfigurationContext context) {
    // Workaround for https://hibernate.atlassian.net/browse/HSEARCH-4724
    // => Hibernate Search doesn't seem to find the Jandex index in the fat JAR.
    try {
        var classesUri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
        logger.info("class uri: "+classesUri);
        var ssp = classesUri.getSchemeSpecificPart();
        logger.info("class uri ssp: "+ssp);
        var jarpath = Path.of(ssp.substring(ssp.indexOf(":") + 1, ssp.indexOf("!")));
        context.annotationMapping().add(JandexUtils.readIndex(jarpath).get());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

}

Projection class:
public class ProductOrderProjection implements Serializable{

private static final long serialVersionUID = 1L;

private String id;
private String href;
private OffsetDateTime cancellationDate;
private String cancellationReason;
private String category;
private OffsetDateTime completionDate;
private String description;
private OffsetDateTime expectedCompletionDate;
private String externalId;
private String notificationContact;
private OffsetDateTime orderDate;
private String priority;
private OffsetDateTime requestedCompletionDate;
private OffsetDateTime requestedStartDate;
private ProductOrderStateType state;
private List<ProductOrderItemProjection> productOrderItem;
private List<RelatedPartyProjection> relatedParty;
private List<ProductOrderBlueprintMappingProjection> productOrderBlueprintMapping;
private AdditionalInfoProjection addInfo;

@ProjectionConstructor
public ProductOrderProjection(String id, String href, OffsetDateTime cancellationDate, String cancellationReason,
		String category, OffsetDateTime completionDate, String description, OffsetDateTime expectedCompletionDate,
		String externalId, String notificationContact, OffsetDateTime orderDate, String priority,
		OffsetDateTime requestedCompletionDate, OffsetDateTime requestedStartDate, ProductOrderStateType state,
		List<ProductOrderItemProjection> productOrderItem, List<RelatedPartyProjection> relatedParty,
		List<ProductOrderBlueprintMappingProjection> productOrderBlueprintMapping,
		AdditionalInfoProjection addInfo) {
	super();
	this.id = id;
	this.href = href;
	this.cancellationDate = cancellationDate;
	this.cancellationReason = cancellationReason;
	this.category = category;
	this.completionDate = completionDate;
	this.description = description;
	this.expectedCompletionDate = expectedCompletionDate;
	this.externalId = externalId;
	this.notificationContact = notificationContact;
	this.orderDate = orderDate;
	this.priority = priority;
	this.requestedCompletionDate = requestedCompletionDate;
	this.requestedStartDate = requestedStartDate;
	this.state = state;
	this.productOrderItem = productOrderItem;
	this.relatedParty = relatedParty;
	this.productOrderBlueprintMapping = productOrderBlueprintMapping;
	this.addInfo = addInfo;
}

}

Hi team please help me on this.

Can anyone help me on this ?

Hi hi @Pavan_kumar_K.M it’s hard to tell what is causing the issue based on the log you’ve provided. But obviously, something is causing the java.lang.StringIndexOutOfBoundsException: begin 3, end -1, length 55. I’d start by tracking down the place this exception is triggered and seeing what’s causing it. You could try debugging within your IDE and adding a breakpoint for StringIndexOutOfBoundsException being thrown if the logs do not provide the actual place it get’s triggered.

@Pavan_kumar_K.M The workaround you’re using is incomplete, there should probably be a guard somewhere to avoid the StringIndexOutOfBoundsException.

But in any case, the workaround is only necessary because of [HSEARCH-4724] - Hibernate JIRA, which has been fixed in the latest snapshot and will be fixed in 6.2.0.Alpha2 when it gets released (don’t ask when, I don’t know: I’m on leave for personal reasons).

1 Like

Hi @yrodiere understood you are on leave , thanks a lot for the time in between, yeah there should be gaurd , but the point is even thou path is fine,

[smart-dev@k3s12103 romsetup]$ cd files/
[smart-dev@k3s12103 files]$
[smart-dev@k3s12103 files]$
[smart-dev@k3s12103 files]$ ll
total 1557756
drwxrwxrwx 2 smart-dev smart-dev 29 Sep 15 19:40 camunda_feasible
drwxrwxrwx 2 smart-dev smart-dev 29 Sep 15 19:40 camunda_mwf
drwxrwxrwx 2 smart-dev smart-dev 75 Sep 20 10:01 ManualTask
-rw-rw-r-- 1 smart-dev smart-dev 165782494 Sep 29 19:16 rom-configuration-service.war
-rw-rw-r-- 1 smart-dev smart-dev 117746610 Sep 23 12:29 rom-configuration-service.warbackup
-rw-rw-r-- 1 smart-dev smart-dev 2 Sep 15 19:44 romconfig.yml
-rw-rw-r-- 1 smart-dev smart-dev 106519835 Sep 29 19:14 rom-core-service.war
-rw-rw-r-- 1 smart-dev smart-dev 106461666 Sep 22 10:20 rom-core-service.warbackup
-rw-rw-r-- 1 smart-dev smart-dev 148740970 Nov 22 08:03 rom-core-svc-null.jar
-rw-rw-r-- 1 smart-dev smart-dev 100774944 Sep 29 19:23 rom-executor-service.war
-rw-rw-r-- 1 smart-dev smart-dev 123388071 Sep 19 08:39 rom-executor-service.warbackup
-rw-rw-r-- 1 smart-dev smart-dev 134567921 Sep 29 19:15 rom-feasibility-service.war
-rw-rw-r-- 1 smart-dev smart-dev 111511526 Sep 15 22:29 rom-feasibility-service.warbackup
-rw-rw-r-- 1 smart-dev smart-dev 79827411 Sep 29 19:20 rom-manual-task-service.war
-rw-rw-r-- 1 smart-dev smart-dev 124478445 Sep 21 19:02 rom-manual-task-service.warbackup
-rw-rw-r-- 1 smart-dev smart-dev 137673647 Oct 7 08:18 rom-microworkflow-service.war
-rw-rw-r-- 1 smart-dev smart-dev 137636792 Sep 29 19:24 rom-microworkflow-service.war_backup
[smart-dev@k3s12103 files]$
[smart-dev@k3s12103 files]$
[smart-dev@k3s12103 files]$
[smart-dev@k3s12103 files]$ pwd
/home/smart-dev/rom/romsetup/files

facing this,
22-11-2022 08:17:52.390 || INFO || org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator || 52 || || || || || || HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
22-11-2022 08:17:52.541 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 23 || || || || || || <<<<<<<<<<<<<<< HibernateSearchMappingConfigurer… >>>>>>>>>>>>>>
22-11-2022 08:17:52.542 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 26 || || || || || || class uri: jar:file:/home/smart-dev/rom/romsetup/files/rom-core-svc-null.jar!/BOOT-INF/classes!/
22-11-2022 08:17:52.543 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 28 || || || || || || class uri ssp: file:/home/smart-dev/rom/romsetup/files/rom-core-svc-null.jar!/BOOT-INF/classes!/
22-11-2022 08:17:52.543 || INFO || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 30 || || || || || || New class uri ssp: /home/smart-dev/rom/romsetup/files/rom-core-svc-null.jar
22-11-2022 08:17:52.571 || ERROR || com.sixdee.rom.core.config.HibernateSearchMappingConfigurer || 36 || || || || || || HibernateSearchMappingConfigurer error:
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:148) ~[?:?]
at com.sixdee.rom.core.config.HibernateSearchMappingConfigurer.configure(HibernateSearchMappingConfigurer.java:32) ~[classes!/:v1.0.1-dev-25]
at org.hibernate.search.mapper.orm.mapping.impl.HibernateOrmMappingInitiator.lambda$configure$0(HibernateOrmMappingInitiator.java:167) ~[hibernate-search-mapper-orm-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
at org.hibernate.search.mapper.orm.mapping.impl.HibernateOrmMappingInitiator.configure(HibernateOrmMappingInitiator.java:164) ~[hibernate-search-mapper-orm-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.engine.common.impl.SearchIntegrationBuilder$MappingBuildingState.collect(SearchIntegrationBuilder.java:269) ~[hibernate-search-engine-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.engine.common.impl.SearchIntegrationBuilder.prepareBuild(SearchIntegrationBuilder.java:147) ~[hibernate-search-engine-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchPreIntegrationService$NotBooted.doBootFirstPhase(HibernateSearchPreIntegrationService.java:248) ~[hibernate-search-mapper-orm-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.bootNow(HibernateOrmIntegrationBooterImpl.java:177) ~[hibernate-search-mapper-orm-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642) ~[?:?]
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[?:?]
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:41) ~[hibernate-search-mapper-orm-6.2.0.Alpha1.jar!/:6.2.0.Alpha1]
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:385) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

Ideally it shouldn,t is what i believe.

By the way i am trying to run rom-core-svc-null.jar.

Code:
package com.sixdee.rom.core.config;

import java.nio.file.Path;

import org.hibernate.search.mapper.orm.mapping.HibernateOrmMappingConfigurationContext;
import org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer;
import org.hibernate.search.util.common.jar.impl.JandexUtils;
import org.jboss.jandex.Index;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component(“searchMappingConfigurer”)
public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {

Logger logger = LoggerFactory.getLogger(HibernateSearchMappingConfigurer.class);

@Override
public void configure(HibernateOrmMappingConfigurationContext context) {

	try {
		
		logger.info("<<<<<<<<<<<<<<<  HibernateSearchMappingConfigurer...  >>>>>>>>>>>>>>");
		
        var classesUri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
        logger.info("class uri: "+classesUri);
        var ssp = classesUri.getSchemeSpecificPart();
        logger.info("class uri ssp: "+ssp);
        String replace = ssp.replace("D:", "d").substring(ssp.indexOf(":") + 1, ssp.indexOf("!"));
        logger.info("New class uri ssp: "+replace);
        var jarpath = Path.of(replace);
        Index index = JandexUtils.readIndex(jarpath).get();
        context.annotationMapping().add(index);
        
    } catch (Exception e) {
        logger.error("HibernateSearchMappingConfigurer error: ",e);
    }
	
}

}

If possible please find some for this.
Not gonna ask when the fix will be released but i really hope it will be soon :slight_smile: