org.apache.ibatis.cache.CacheException: Error serializing object. Cause: java.io.NotSerializableException: com.baizhi.entity.User
at org.apache.ibatis.cache.decorators.SerializedCache.serialize(SerializedCache.java:100)
atorg.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.io.NotSerializableException: com.baizhi.entity.User
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
org.apache.ibatis.cache.decorators.SerializedCache.serialize(SerializedCache.java:96)
… 47 more
Reason: when using the L2 cache in mybatis, the entity class must be serialized. Implements serializable. My mapper file uses tags and the L2 cache provided by mybatis, so it must be serialized in my entity class
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.baizhi.dao.UserDao">
<!-- The L2 cache is used here The entity class must implement the serialization interface -->
<cache/>
<select id="selectAllUsers" resultType="User">
select id,
phone,
password,
name,
from c_user
</select>
</mapper>
Similar Posts:
- [Solved] mybatis Multi-Module Error: Invalid bound statement (not found)
- [Solved] Caused by: org.xml.sax.SAXParseException: Premature end of file.
- [Solved] Mybatis: the binding mapper cannot be found Error: Org.apache.ibatis.binding.bindingexception: invalid bound statement (not found)
- java.lang.Exception: No runnable methods
- Cause: java.lang.ClassNotFoundException: Cannot find class: com.kuang.pojo.User
- com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class tonels.
- [Solved] Caused by: java.lang.ClassNotFoundException: org.mybatis.logging.LoggerFactory
- JUnit error: Java. Lang. exception: the test class should have only one public constructor
- junitjava.lang.Exception: No tests found matching
- Springboot: solve the problem of failed to load ApplicationContext