Spring boot Spring引导mapstruct和modelMapper比较容易混淆的问题

Spring boot Spring引导mapstruct和modelMapper比较容易混淆的问题,spring-boot,spring-data-jpa,mapstruct,modelmapper,Spring Boot,Spring Data Jpa,Mapstruct,Modelmapper,我有以下情况,我使用spring数据获取实体列表, 并尝试使用mapstruct将这些实体映射到DTO列表,而不是使用modelMapper映射这些实体(我使用这两种映射来分析慢度问题) public List getListDto(字符串参数1,整数参数2){ //Bloc1:mapstruct映射 List result1=entityArepository.findAllByFilter(字符串参数1,整数参数2).stream() .map(entityA->mapstructMappe

我有以下情况,我使用spring数据获取实体列表, 并尝试使用mapstruct将这些实体映射到DTO列表,而不是使用modelMapper映射这些实体(我使用这两种映射来分析慢度问题)

public List getListDto(字符串参数1,整数参数2){
//Bloc1:mapstruct映射
List result1=entityArepository.findAllByFilter(字符串参数1,整数参数2).stream()
.map(entityA->mapstructMapper.toDto(entityA))
.collect(Collectors.toList());
//结束区1
//Bloc2:modelMapper映射
List result2=entityArepository.findAllByFilter(字符串参数1,整数参数2).stream()
.map(entityA->modelMapper.map(entityA,EntityADto.class))
.collect(Collectors.toList());
//结束集团2
}
我发现慢度可能来自FetchType,因为第一个执行的块非常慢,但下一个块将立即执行。例如,如果我将Bloc2放在getListDTO方法的顶部,将Bloc1放在下面,Bloc2将运行得非常慢(大约1分钟),Bloc1将运行得非常快(大约0.1秒)

我尝试使用FetchMode.JOIN和JOIN fetch解决此问题,但结果相同:

@Repository
@RepositoryRestResource(exported = false)
public interface EntityArepository extends JpaRepository< EntityA, Integer> {
   @Fetch(FetchMode.JOIN)
    @Query(" SELECT o FROM EntityA o " +  
            " and (o.propertyOne = :argument1)"+
            " and (o.propertyTwo = :argument2 )"
    )
    List<EntityA> findAllByFilter(@Param("argument1") String argument1,
                                              @Param("argument2") Integer argument2 );

@存储库
@RepositoryRestResource(导出=false)
公共接口EntityArepository扩展了JpaRepository{
@Fetch(FetchMode.JOIN)
@查询(“从实体中选择o”+
“和(o.propertyOne=:argument1)”+
“和(o.propertyTwo=:argument2)”
)
列出findAllByFilter(@Param(“argument1”)字符串argument1,
@参数(“argument2”)整数argument2);
有什么建议吗


提前感谢

我不确定您使用的查询是否正确,就像它应该是“where(o.propertyOne为null或o.propertyOne=:argument1)和…”.Join fetch用于获取单个操作而不是多个操作中所需的其他实体。谢谢,这里的操作是什么意思?您是否知道为什么放置在顶部的块总是比放置在下面的块运行得更快(即使我交换了块的位置)通过多个操作,我的意思是hibernate将创建和执行多个查询。我不确定为什么第一次执行的时间比第二次要长。好的,我明白你的意思,但请注意,“对于FetchMode.JOIN set,FetchType被忽略,而查询总是急切的”from.和这个渴望类型是我试图达到的,看看它是否可以帮助好的,你在做实体连接吗?如果是这样,那么只有连接会有帮助,否则它不会有任何效果。使用application.properties;spring.jpa.show sql=true中的以下配置,查看运行时生成的查询,它将帮助你更好地理解什么执行查询。
@Repository
@RepositoryRestResource(exported = false)
public interface EntityArepository extends JpaRepository< EntityA, Integer> {
   @Fetch(FetchMode.JOIN)
    @Query(" SELECT o FROM EntityA o " +  
            " and (o.propertyOne = :argument1)"+
            " and (o.propertyTwo = :argument2 )"
    )
    List<EntityA> findAllByFilter(@Param("argument1") String argument1,
                                              @Param("argument2") Integer argument2 );