在集成我们现有的应用程序之前,我正在试验Hibernatesearch 6.2.0的投影特性。
我用JHIPSTER 样本工程创建了一个spring引导项目。并在POM.XML和application*.yml中添加了Hibernate搜索依赖项和配置。使用JHipster,因为它帮助我处理样板代码和假数据。
已经将pom.xml配置为-parameters和jandex。应用程序成功运行并将数据加载到数据库中。我可以用我们根据文档编写的实用工具来编制大量索引。
然而,当尝试搜索带有投影的数据时,我们收到的是误差Exception in searchWithProjection() with cause = 'NULL' and exception = 'HSEARCH700112: Invalid object class for projection: com.sample.shop.service.projections.dto.Address. 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.'。如果我们搜索时没有投影,那么相同的查询/逻辑就能很好地工作。
例如。如果您在上面链接的存储库中查看文件AddressResource.java & AddressService.java;您可以分别为投影和无投影找到两个实现。虽然没有投影的那个非常好,但是有项目的那个却抛出了这个错误。
我觉得这可能是一些配置问题,但无法自己解决。感谢您对配置/代码方法的帮助。
请告知,我已经看过了这张折叠式票:
发布于 2022-10-21 15:35:24
谢谢你的复制人。这是个bug:https://hibernate.atlassian.net/browse/HSEARCH-4724
我建议了一个解决办法:https://github.com/anothergoodguy/spring-data-hibernate-search/pull/1
简言之:
package com.sample.shop.config;
import java.net.URISyntaxException;
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.springframework.stereotype.Component;
@Component("searchMappingConfigurer")
public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {
@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();
var ssp = classesUri.getSchemeSpecificPart();
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);
}
}
} jpa:
properties:
hibernate.search.mapping.configurer: bean:searchMappingConfigurer还有哇哦。
注意,这只是一个解决方案,依赖于可能随时中断的内部代码。但是,嗯,至少它能工作,所以在bug被修复之前,它是可以的。
发布于 2022-10-21 12:39:46
下面是运行应用程序的说明:
所有需要的生态系统,如Elasticsearch,kibana和MySql都是在eco.yml文件中添加到src/main/docker/eco.yml下的--请使用下面的命令将生态系统提升到docker-compose -f src/main/docker/eco.yml up -d && docker-compose -f src/main/docker/eco.yml logs -f
在不同的终端选项卡/窗口上,使用以下命令./mvnw clean package -Pprod,api-docs -Dskip.Tests -Dmaven.test.skip=true构建应用程序,以运行应用程序,运行以下命令java -jar target/shop-app-0.0.1-SNAPSHOT.jar
一旦应用程序启动,它将显示它在[http://localhost:8080]上列表。请在浏览器上打开相同的url,并使用默认管理员用户:admin和Password:admin登录。然后,请从管理员菜单和API菜单项导航到swagger。
我们需要对已从同一swagger窗口中加载的伪造数据进行批量索引:通过在资源上执行/api/mass/index上的post,弹性搜索批量索引API
那么请转到address-resource:
/api/_search/addresses访问aa -这将导致成功/_search/addresses/projection的aa --这将导致失败https://stackoverflow.com/questions/74149716
复制相似问题