首页 新闻 搜索 专区 学院

mybatis里面使用二级缓存得到的对象hashCode相同,输入==号为false,二级缓存得到的对象是否是同一个对象?

0
[待解决问题]

        SqlSessionFactory sqlSessionFactory = SqlSessionUtils.getSqlSessionFactory();

        SqlSession sqlSession = sqlSessionFactory.openSession();
        SqlSession sqlSession2 = sqlSessionFactory.openSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User userById = mapper.findUserById(42);
        System.out.println(userById.hashCode());  //936580213
        sqlSession.close();

        UserMapper mapper2 = sqlSession2.getMapper(UserMapper.class);
        User userById2 = mapper2.findUserById(42);
        System.out.println(userById.hashCode());  //936580213
        sqlSession2.close();

        System.out.println(userById == userById2);  //false
木禾兄的主页 木禾兄 | 初学一级 | 园豆:196
提问于:2020-07-12 08:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册