반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 서울숲누룽지통닭구이
- 꼴뚜기회
- ELK
- npm
- 한남동맛집
- 퇴사후공무원
- 스페인여행
- 방이편백육분삼십
- 국가직
- 성신여대맛집
- 통영예쁜카페
- 성신여대편백집
- 통영에어비앤비
- 통영여행
- react
- springboot
- ubuntu자바설치
- 뚝섬역맛집
- 자바스크립트에러처리
- 성북구맛집
- 돈암동맛집
- 파이썬
- JavaScript
- tomcat7
- 통영
- 공무원
- 방이편백육분삼십성신여대
- gradle
- 한성대맛집
- 영화추천
Archives
- Today
- Total
코린이의 기록
[Hibernate] org.springframework.dao.EmptyResultDataAccessException: No entity found for query; 본문
Framework/hibernate
[Hibernate] org.springframework.dao.EmptyResultDataAccessException: No entity found for query;
코린이예요 2018. 7. 9. 22:54반응형
Hibernate 관련 에러 발생.
Hibernate framework를 사용하던중 아래와 같은 error가 발생하였다.
org.springframework.dao.EmptyResultDataAccessException: No entity found for query;
nested exception is javax.persistence.NoResultException: No entity found for query
에러 로그
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | An unexpected error has occurred <!-- org.springframework.dao.EmptyResultDataAccessException: No entity found for query; nested exception is javax.persistence.NoResultException: No entity found for query at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:301) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:106) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403) at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) ....... 생략 at java.lang.Thread.run(Thread.java:662) Caused by: javax.persistence.NoResultException: No entity found for query at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:286) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getSingleResult(CriteriaQueryCompiler.java:257) at com.alticast.cas3.administrator.service.impl.StatSubscriberServiceImpl.countGroupByRegioncode(StatSubscriberServiceImpl.java:134) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) ... 104 more | cs |
원인 분석
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @Override public Long countGroupByRegioncode(StatSubscriberCommand command) { CriteriaBuilder criteriaBuilder = super.entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class); // criteriaQuery.distinct(true); // TODO: when active, breaks the sort // on x-to-one property! // from Root<StatSubs> root = criteriaQuery.from(StatSubs.class); // select criteriaQuery = criteriaQuery.select(criteriaBuilder.count(root)); // predicate Predicate predicate = getPredicate(root, criteriaBuilder, command); if (predicate != null) { criteriaQuery = criteriaQuery.where(predicate); } // group by criteriaQuery.groupBy(root.get("statSubsPK").<String> get("statDate")); TypedQuery<Long> typedQuery = super.entityManager.createQuery(criteriaQuery); return typedQuery.getSingleResult(); } | cs |
line 20 : statDate entity가 없는데 groupby로 지정하여 query를 수행하였던 것이 원인
수정 전
1 2 3 | TypedQuery<Long> typedQuery = super.entityManager.createQuery(criteriaQuery); return typedQuery.getSingleResult(); | cs |
수정 후
1 2 3 4 5 6 7 | TypedQuery<Long> typedQuery = super.entityManager.createQuery(criteriaQuery); try { return typedQuery.getSingleResult(); } catch (NoResultException nre) { return 0l; } | cs |
NoResultException 처리를 해주어서 해결하였다.
반응형
'Framework > hibernate' 카테고리의 다른 글
[hibernate] org.hibernate.event.internal.DefaultLoadEventListener - HHH000327: Error performing load command (0) | 2019.02.19 |
---|
Comments