解决客户端 query did not return aunique result:2
2017-11-08 09:31
525 查看
解决客户端 query did not return aunique result:2
从字面意思很好理解,查询出了两条相同的记录,说明数据库出现了脏数据,反复检验程序并未发现有bug。
最终 确定 是由于 程序是布在 两个节点上。当同一用户发出两次相同的请求时,执行的两次保存数据的动作 ,被分别分配在了两台节点服务上边,导致了脏数据的产生。
解决办法: 系统架构是用的是 hibernate。则使用框架自带 的乐观锁 来 保证 事务的 完整性
乐观锁的工作原理:读取出数据时,将此版本号一同读出,之后更新时,对此版本号加一。此时,将提交数据的版本数据与数据库表对应记录的当前版本信息进行比对,如果提交的数据版本号大于数据库表当前版本号,则予以更新,否则认为是过期数据
从字面意思很好理解,查询出了两条相同的记录,说明数据库出现了脏数据,反复检验程序并未发现有bug。
最终 确定 是由于 程序是布在 两个节点上。当同一用户发出两次相同的请求时,执行的两次保存数据的动作 ,被分别分配在了两台节点服务上边,导致了脏数据的产生。
解决办法: 系统架构是用的是 hibernate。则使用框架自带 的乐观锁 来 保证 事务的 完整性
乐观锁的工作原理:读取出数据时,将此版本号一同读出,之后更新时,对此版本号加一。此时,将提交数据的版本数据与数据库表对应记录的当前版本信息进行比对,如果提交的数据版本号大于数据库表当前版本号,则予以更新,否则认为是过期数据
@Entity @Table(name = "customer") @ApiModel public class Customer extends BaseEntity { @Version @Column(nullable = false) private Long version;
相关文章推荐
- query did not return a unique result
- org.hibernate.NonUniqueResultException: query did not return a unique result: 2
- 【项目经验】org.hibernate.NonUniqueResultException: query did not return a unique result: 3
- query did not return a unique result: 3 错误
- org.hibernate.NonUniqueResultException: query did not return a unique result: 2
- query did not return a unique result
- org.hibernate.NonUniqueResultException: query did not return a unique result: 3
- org.hibernate.NonUniqueResultException: query did not return a unique result: 2
- query did not return a unique result: 2
- NonUniqueResultException: query did not return a unique result: 2
- query did not return a unique result: 275
- 异常:org.hibernate.NonUniqueResultException: query did not return a unique result: 5
- SQL Server set nocount on 与JDBC: The statement did not return a result
- The provider did not return a ProviderManifestToken string. 的解决方法
- SQLServerException: The statement did not return a result set
- java使用jdbc调用hive出现The query did not generate a result set!
- 关于method not exist:think\db\Query->render错误解决方法
- Error converting document: task did not complete within timeout解决方法
- CocoaPods did not set the base configuration of your project 问题解决方式
- 关于APUE第十六章的客户端程序返回Servname not supported for ai_socktype错误的解决方法