SpringMVC+Mybatis 出现新增数据偶尔查不到的情况。 5C

情况1:
重启服务后,新增数据的插入没有问题,数据库中能查到,但是项目中查询的结果是浮动的,
即偶尔查询正确,偶尔会出现本次重启服务后新增数据没查到,仅查询到原有数据(重启服务之前
已有的数据)的情况;
情况2:
在重启服务后,原有的数据不会出现查询时丢数据的情况;
情况3:
已上现象为整个项目中普遍存在的情况,即任意表都会出现上述情况;
情况4:
上述查询问题即使在不存在事务的简单查询中也存在;

附示例:
以下为筛选日志结果:
数据库记录数为3条,查询结果为2和3,并且一直持续存在;
、、、
[ERROR]-[Thread: 201712022233077548st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223308468Dst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233088862st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233093165st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223309843Fst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233102741st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233109243st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233116034st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233123791st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233130438st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233136847st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233144678st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223314845Cst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233152237st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223315588Est.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233159568st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223316739Bst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233173903st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233180297st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223318843Cst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233194784st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233201245st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223320520Fst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233210862st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233214528st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223321817Cst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233224558st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223323240Cst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223323909Dst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233245542st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233253420st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233259899st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223326365Fst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233267379st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233271049st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223327605Est.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233282475st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233288928st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233298680st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 20171202223330510Dst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233311501st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233319217st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223332300Ast.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 201712022233326794st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223333046Dst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===2
[ERROR]-[Thread: 20171202223333414Cst.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233342048st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233348460st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233354911st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
[ERROR]-[Thread: 201712022233362800st.ParameterRequest.printTheResponsePara()]: ===Para:[1, 2]===3
、、、
以下为查询结果为2时的查询sql
、、、
[20171202223331921753A0] [DEBUG] org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@82fbac2]
[20171202223331921753A0] [DEBUG] org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@82fbac2] from current transaction
[20171202223331921753A0] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - ==> Preparing: select * from orders WHERE member_id= ? and order_state IN ( ? , ? ) order by id desc limit ?,?
[20171202223331921753A0] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - ==> Parameters: 24(String), 1(Integer), 2(Integer), 0(Integer), 10(Integer)
[20171202223331921753A0] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - <== Total: 2
、、、

以下为查询结果为3时的查询sql
、、、

[20171202223333414C2A60] [DEBUG] o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
[20171202223333414C2A60] [DEBUG] o.m.s.t.SpringManagedTransaction - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@708060c1] will not be managed by Spring
[20171202223333414C2A60] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - ==> Preparing: select * from orders WHERE member_id= ? and order_state IN ( ? , ? ) order by id desc limit ?,?
[20171202223333414C2A60] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - ==> Parameters: 24(String), 1(Integer), 2(Integer), 0(Integer), 10(Integer)
[20171202223333414C2A60] [DEBUG] c.T.d.s.w.o.O.getOrdersForMulti - <== Total: 3
[20171202223333414C2A60] [DEBUG] org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3103e6df]
[20171202223333414C2A60] [DEBUG] o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
[20171202223333414C2A60] [DEBUG] org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
[20171202223333414C2A60] [DEBUG] org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@222f700b] was not registered for synchronization because synchronization is not active
、、、

10个回答

你把配置好好看一下 可能是配置上出了问题

评论失败都给我推上去了

看看有没有提交,commit一下,把事务关掉试试,或者数据库没提交

得跟踪一下线程thread dump(Jstack命令),ERROR得看哪报错了。

你把配置好好看一下 可能是配置上出了问题

代码中再添加的时候有没有使用缓存,还有查询的时候有没有使用缓存,如果是经常修改的数据就不要使用缓存,还有就是在添加的过程有没有做事务提交

1. 可能是事务配置问题,在第二次查询时,第一次插入的数据事务还没有提交。
2。如果是用了缓存,可能在第二次查询时,先在库里看一下,数据库是否存在,如果查询但是查不到数据,
有可能命中缓存,但是缓存配置策略错误有关,除了查询,其他影响数据的操作都应该清除缓存。
 3.最后就是看看你代码接受的有没有问题了

可能是你的事务没有自动提交的问题

你设置了缓存了吗?

你看看你的配置文件里,再看看你的方法

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐