Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么是;org.hibernate.type.CollectionType:已创建集合包装器“;方法_Hibernate_Spring Data Jpa_Lazy Loading_One To Many_Many To One - Fatal编程技术网

什么是;org.hibernate.type.CollectionType:已创建集合包装器“;方法

什么是;org.hibernate.type.CollectionType:已创建集合包装器“;方法,hibernate,spring-data-jpa,lazy-loading,one-to-many,many-to-one,Hibernate,Spring Data Jpa,Lazy Loading,One To Many,Many To One,懒散加载在我的应用程序中似乎不起作用,我也不知道为什么 我有如下相关实体: public class Participant { private Long id; @OneToMany( mappedBy = "participant", fetch = FetchType.LAZY ) private Set<RequestProduct> requestProducts; @OneToMany( mappedB

懒散加载在我的应用程序中似乎不起作用,我也不知道为什么

我有如下相关实体:

public class Participant {
    private Long id;

    @OneToMany( mappedBy = "participant", fetch = FetchType.LAZY )
    private Set<RequestProduct>                  requestProducts;

    @OneToMany( mappedBy = "participant", fetch = FetchType.LAZY )
    private Set<ParticipantRank>                 participantRanks;

    @OneToMany( mappedBy = "participant", fetch = FetchType.LAZY )
    private Set<RequestProductParticipant>       requestProductParticipants;
}
以及存储库:

public interface RequestProductRepository extends JpaRepository<RequestProduct, Long> { 

 Optional<RequestProduct> findByIdentifier( String identifier );
}
调用3个从3个表中加载所有数据的大
select
查询。发生了什么事? 这正常吗


谢谢你的解释

刚刚遇到了这个问题并找到了解决方案。发生这种情况的原因是集合的类型为Set。默认情况下,Java会通过检查对象的所有属性是否等于计数器对象来检查对象集中是否已经存在对象,以便获取所有参与者集合

我通过覆盖我的模型的equalshash方法解决了这个问题,并且仅使用ID对它们进行比较:

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    RequestProduct requestProduct = (RequestProduct) o;
    return Objects.equals(id, requestProduct.id);
}

@Override
public int hashCode() {
    return Objects.hash(id);
}
对不起,我迟到了将近一年=/

@Transactional
@Service
public class ServiceImpl {
   private RequestProductRepository repo;

   public void modifyRequestProduct(String identifier){ 
    //THE PROBLEM IS HERE
    Optional<RequestProduct> product = repo.findByIdentifier( identifier );
  }
}
[ taskExecutor-7] org.hibernate.type.CollectionType        : Created collection wrapper: [org.module.module.models.Participant.requestProducts#1]
[ taskExecutor-7] org.hibernate.type.CollectionType        : Created collection wrapper: [org.module.module.models.Participant.participantRanks#1]
[ taskExecutor-7] org.hibernate.type.CollectionType        : Created collection wrapper: [org.module.module.models.Participant.requestProductParticipants#1]
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    RequestProduct requestProduct = (RequestProduct) o;
    return Objects.equals(id, requestProduct.id);
}

@Override
public int hashCode() {
    return Objects.hash(id);
}