Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements
Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:492)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:54)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:100)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:91)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:454)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:432)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 51
该异常是getSingleResult()方法获取的值不是唯一,经反复查看发现数据库中有多条相同条件的数据,所有报了该异常!!
这个方法经过查阅发现很局限,他要求必须只能返回一个值:多了抛出NonUniqueResultException异常,查询不到结果抛出NoResultException异常。所以方法慎用!
在使用时一定要加try catch( NoResultException e),这个方法假如查不到值并不会返回null而是抛出NoResultException异常
Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements的更多相关文章
- cloudera-scm-server启动时出现Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection问题解决方法(图文详解)
问题现象 查看 [root@cmbigdata1 cloudera-scm-server]# pwd /var/log/cloudera-scm-server [root@cmbigdata1 clo ...
- 【spring data jpa】报错如下:Caused by: javax.persistence.EntityNotFoundException: Unable to find com.rollong.chinatower.server.persistence.entity.staff.Department with id 0
报错如下: org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.rollong.chi ...
- Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested ...
- result returns more than one elements此种错误,解决
场景:公司产品开发完成后,接入第三方厂商,在进行接口联调的时候出现此问题.此接口报文中的每一个数据都要进行校验,有些是与已经存入产品数据库中的数据进行对比,看是否存在. 问题:在测试中,有些测试没有问 ...
- 使用Spring Data JPA查询时,报result returns more than one elements异常
public static <T> T get(String hql, Class<T> t) { EntityManager em = getFactory().create ...
- Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode
进行 spring mvc jpa整合时.Junit方法测试时. 异常: org.springframework.beans.factory.BeanCreationException: Error ...
- Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index
1.错误描述 WARN:2015-05-01 16:45:37[main] - Exception encountered during context initialization - cancel ...
- Caused by: java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery
1.错误描述 2014-7-12 21:06:37 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreat ...
- Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
随机推荐
- superReducedString-hankerrank
Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string t ...
- 20164301 Exp4 恶意代码分析
Exp4 恶意代码分析 实验目标 1.是监控你自己系统的运行状态,看有没有可疑的程序在运行. 2.是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinte ...
- zabbix4.0离线快速编译安装(编译安装方法)
本博客已整理更新至第二版.更新与2019.4.17 其实这个主要是想试一下离线编译安装的具体步骤,记得要配置好本地yum云,因为我们需要使用yum,yum能帮我们自动解决很多依赖问题.发现最主要的问题 ...
- jquery怎么选择嵌套的第一层的li
$(".ra").click(function(){ var id=$(this).children("ul").attr("id"); i ...
- docker-solr 使用host模式修改默认的8983端口号
1.使用root账号进入docker-solr docker exec -it 127627ab6247 -u root /bin/bash 2.安装vim apt-get update apt-ge ...
- 0.5px border 实现方案
<div class='thin-border'></div> .thin-border { position: relative; width: 40px; height: ...
- C#,调用dll产生 "尝试读取或写入受保护的内存 。这通常指示其他内存已损坏。"的问题
由于易语言与c#做的DESC加解密方式,返回的数据不一致,所以,我用易语言写了一个dll,供c#调用, 结果在post的时候,有时候能正确返回数据,有时候则不能正常返回,而是返回空数据(c#没有做异常 ...
- 黄聪:C#中CefSharp的简单使用
C#中CefSharp的简单使用 https://blog.csdn.net/qq_26712977/article/details/78282995
- mac中更改xampp的根目录
方法一: 1 打开 应用程序->XAMPP->xamppfiles->etc->httpd.conf 文档 2 commond+f搜索htdocs,搜到如下结果 # Docum ...
- IDEA汉化
1.- 汉化包 提取码: 4mbq 2.打开IDEA,执行下列操作:在主界面选择File → Settings → Appearance&Behavior → Appearance → 勾选O ...