我想缓存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
无法正常工作
这是一个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)进行缓存,但由于列表是可序列化的,但列表元素不是,因此失败。