I want to cache result of Interface-based Projections
but I got this error
Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize '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();
}
it seems extends Serializable
not working
This is a Spring issue, buried in the depths is this:
java.io.NotSerializableException: org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor
Might be another occurrance of this
As a workaround, you could change
List<NamesOnly> findByCustomerId( @Param("customerId") List<String> customerId);
to
List<String> findByCustomerId( @Param("customerId") List<String> customerId);
as your projection only returns a single column, firstName
, which presumably is a string.
Without @Cacheable
what you get back is a list ( serializable ) of proxy classes ( not serializable ). With @Cacheable
the list gets sent to the distributed store (Hazelcast) for caching, and this fails as the list is serializable but the list elements aren't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.