博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jpa查询记录重复
阅读量:6571 次
发布时间:2019-06-24

本文共 3060 字,大约阅读时间需要 10 分钟。

hot3.png

今天遇到一个bug,使用jpa查询数据,发现大部分的数据总有两条数据的状态字段一致的,.然后可以了debugger之旅. 数据结构如下

{"content":[{"orderno":"20170227195026075","shopName":"新泰市市区魅族专卖店","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098201","rowind":"437452","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":8.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"},{"orderno":"20170227195026075","shopName":"新泰市市区魅族专卖店","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098201","rowind":"437452","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":8.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"},{"orderno":"20170227194909256","shopName":"新泰市市区魅族专卖店","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098201","rowind":"437000","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":6.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"},{"orderno":"20170227194909256","shopName":"新泰市市区魅族专卖店","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098201","rowind":"437000","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":6.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"},{"orderno":"20170228175156770","shopName":"新泰市翟镇联合通讯","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098204","rowind":"438960","namepath":"山东省泰安市新泰市","orderStatus":"业务签收","income":6.0,"phoneCount":"1","incometype":"出库收益","createTime":"2017-02-28","payStatus":"已付款","orderPayType":"(线上支付)"},{"orderno":"20170228211134400","shopName":"新泰市翟镇方孜通讯","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098223","rowind":"439407","namepath":"山东省泰安市新泰市","orderStatus":"订单取消","income":0.0,"phoneCount":"1","incometype":"无收益","createTime":"2017-02-28","payStatus":"未付款","orderPayType":""},{"orderno":"20170227111243885","shopName":"新泰市小协镇刘和手机广场","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098221","rowind":"439500","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":6.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"},{"orderno":"20170227111243885","shopName":"新泰市小协镇刘和手机广场","userId":"A37098205160","cmonth":"2017-02","truename":"艾常松","regionId":"37098221","rowind":"439500","namepath":"山东省泰安市新泰市","orderStatus":"客户签收","income":6.0,"phoneCount":"1","incometype":"实时收益","createTime":"2017-02-27","payStatus":"已付款","orderPayType":"(现金)"}],"totalElements":0,"totalPages":56,"last":true,"numberOfElements":15,"first":false,"sort":null,"size":20,"number":55}

这里显示的数据在表里都有两个.

查询条件

把查询的sql粘了出来,执行一遍,未发现问题.

枚举

因为是用枚举来表示状态,所以先想到了是不是枚举有问题,瞎折腾了一个小时,发现无任何改变.

换成String

枚举无用,换成String,折腾了半个小时,问题还是一样.挨个观察了20条数据,发现订单号相同的数据只有一个状态,莫非是把订单号相同状态的数据替换了.

更新主键字段

看了一下自己的实体类,果然是以订单号为主键.问题就在这了,然后改了下主键字段,再查询时,其状态就不重复了.

总结,犯了个错误,即主键无重复,因为orderNo有重复的,所以用它做主键查询才出现这个问题.

转载于:https://my.oschina.net/u/1590027/blog/864967

你可能感兴趣的文章
mysql中利用游标遍历表中的数据时未正常获取数据
查看>>
Iptables模块recent应用
查看>>
Linux Ext3、Ext4误删文件恢复 extundelete
查看>>
AIX添加硬盘后做rootvg镜像及取消
查看>>
Windows性能计数器
查看>>
NX支持的环境变量(转)
查看>>
基于javascript的Ajax
查看>>
ORACLE中序列问题
查看>>
我的友情链接
查看>>
[实践]Sonar Xcode8兼容
查看>>
数字金额到汉字的转换
查看>>
PostgreSQL 9.4版本的物化视图更新
查看>>
userdel命令
查看>>
linux /etc/inittab 的六个运行级别简单理解
查看>>
Ubuntu Server 14.04 ftp
查看>>
linux系统wc命令详解
查看>>
Windows7 下边查看80端口被哪个服务占用了
查看>>
进度条(HUD) 第三方库
查看>>
CentOS 5.5升级内核到2.6.28并支持XFS/L7
查看>>
"no acceptable C compiler found in $PATH"解决手记
查看>>