title: How can I store HashMap in Redis
body: <p>I have to store an object in Redis use Spring Redis. The Object is </p>
  
  <pre><code>@RedisHash(value = "shoppingcart")
  public class ShoppingCart {
    @Id
    private String cartGuid;
    private Map&lt;String, List&lt;CartItemDto&gt;&gt; promotionProductMap = new LinkedHashMap&lt;String, List&lt;CartItemDto&gt;&gt;();
    private LinkedList&lt;CartItemDto&gt; cartItems = new LinkedList&lt;&gt;();
  ....
  }
  </code></pre>
  
  <p>CartItemDto look like this</p>
  
  <pre><code>public class CartItemDto implements Serializable {
  
    private static final long serialVersionUID = -7047005024550867744L;
    private String cartItemId;
    private Long productId;
  ...
  }
  </code></pre>
  
  <p>I have an repository to save into Redis</p>
  
  <pre><code>@Repository
  public interface ShoppingCartRepository extends CrudRepository&lt;ShoppingCart, String&gt; {
  }
  </code></pre>
  
  <p>But when I tried to store shoppingCart by</p>
  
  <pre><code>shoppingCartRepository.save(shoppingCart);
  </code></pre>
  
  <p>It throw Exception </p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Target bean of type java.util.LinkedList is not of type of the persistent entity (com.test.CartItemDto)!
      at org.springframework.util.Assert.isTrue(Assert.java:68) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
      at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:397) ~[spring-data-commons-1.12.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver.doResolveIndexesFor(PathIndexResolver.java:92) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver.access$000(PathIndexResolver.java:50) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver$1.doWithPersistentProperty(PathIndexResolver.java:115) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver$1.doWithPersistentProperty(PathIndexResolver.java:95) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:312) ~[spring-data-commons-1.12.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver.doResolveIndexesFor(PathIndexResolver.java:95) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.PathIndexResolver.resolveIndexesFor(PathIndexResolver.java:79) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.MappingRedisConverter.write(MappingRedisConverter.java:357) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.convert.MappingRedisConverter.write(MappingRedisConverter.java:109) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.redis.core.RedisKeyValueAdapter.put(RedisKeyValueAdapter.java:183) ~[spring-data-redis-1.7.5.RELEASE.jar:?]
      at org.springframework.data.keyvalue.core.KeyValueTemplate$1.doInKeyValue(KeyValueTemplate.java:168) ~[spring-data-keyvalue-1.1.5.RELEASE.jar:?]
      at org.springframework.data.keyvalue.core.KeyValueTemplate$1.doInKeyValue(KeyValueTemplate.java:158) ~[spring-data-keyvalue-1.1.5.RELEASE.jar:?]
      at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:377) ~[spring-data-keyvalue-1.1.5.RELEASE.jar:?]
      ... 156 more
  </code></pre>
  
  <p>If I remove promotionProductMap, it can save shoppingCart
  I don't know why it can't save Hashmap, with List it can
  Anyone know how can I save a Hashmap to Redis?</p>