【问题标题】:HazelcastSerializationException: Failed to serialize Interface-based ProjectionsHazelcastSerializationException:无法序列化基于接口的投影
【发布时间】:2019-03-04 15:34:10
【问题描述】:

我想缓存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 不起作用

【问题讨论】:

  • 没有@Cacheable 是否可以工作? NamesOnly 没有字段
  • 确保它在没有@Cacheable的情况下也能正常工作
  • 好的,让我深入检查一下

标签: java spring-data-jpa hazelcast projection


【解决方案1】:

这是一个Spring问题,埋在深处的是这样的:

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

可能是this的另一次出现

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

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

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

因为您的投影只返回一列 firstName,这可能是一个字符串。

没有@Cacheable,你得到的是一个代理类列表(可序列化)(不可序列化)。 使用@Cacheable,列表被发送到分布式存储(Hazelcast)进行缓存,这会失败,因为列表是可序列化的,但列表元素不是。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 2020-08-19
    相关资源
    最近更新 更多