HazelcastSerializationException:无法序列化基于接口的投影

问题描述 投票:0回答:1

我想缓存Interface-based Projections的结果,但是我收到了这个错误

引起:com.hazelcast.nio.serialization.HazelcastSerializationException:无法序列化'java.util.ArrayList'

@Repository
    public interface CustomerRepository extends JpaRepository<CustomerRepository, Long> {       
        @Cacheable(value = "customer")
        @Query("select c.first_name as firstName from customer where customer_id in :customerId")
        List<NamesOnly> findByCustomerId( @Param("customerId") List<String> customerId);
    }

    public interface NamesOnly extends Serializable {

        String getCustomerFirstName();

    }

它似乎扩展Serializable无法正常工作

java spring-data-jpa hazelcast projection
1个回答
1
投票

这是一个Spring问题,深埋在这里:

java.io.NotSerializableException: org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor

可能是qazxsw poi的另一种情况

作为一种解决方法,您可以改变

this

List<NamesOnly> findByCustomerId( @Param("customerId") List<String> customerId);

因为你的投影只返回一个列List<String> findByCustomerId( @Param("customerId") List<String> customerId); ,可能是一个字符串。

如果没有firstName,你得到的是一个代码类列表(可序列化)(不可序列化)。使用@Cacheable,列表将被发送到分布式存储(Hazelcast)进行缓存,但由于列表是可序列化的,但列表元素不是,因此失败。

© www.soinside.com 2019 - 2024. All rights reserved.