hibernate报org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException错误

本文解决了一个在Hibernate关联查询中出现的NonUniqueDiscoveredSqlAliasException错误,原因是两个表中有相同的列名导致。通过为重复的列取别名的方法解决了此问题。

hibernate报org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException错误

百度查找的答案:

原因:关联查询的两个表有相同的列名,

Query须要使用别名来区分相同名称的列。

解决方法:两个表中相同的列,只去其中的一个就可以了

 

自己的问题:

查询结果中出现了两列同名的情况,给其中一列取别名;

 

出问题的sql语句(报错前没有eid)

select uu.id, uu.user_login_name, ee.id eid, ee.real_name, uu.state
  from (select u.id, u.user_login_name, u.employee_id, u.state
          from ims_ot_user u
         where exists
         (select eo.employee_id
                  from ims_rt_employee_organization eo
                 where exists
                 (select *
                          from (select t.id
                                  from (select org.id,
                                               oo.oo.super_organization_id
                                          from ims_ot_organization org
                                          left join ims_rt_organization oo
                                            on org.id = oo.organization_id) t
                                 start with t.id = '8a847c0b55ca7b730155cad5cd50001d'
                                CONNECT BY PRIOR t.id = t.super_organization_id) org1
                         where org1.id = eo.organization_id)
                   and eo.employee_id = u.employee_id)) uu
  left join ims_ot_employee ee
    on uu.employee_id = ee.id
Union
select uu.id, uu.user_login_name, ee.id eid, ee.real_name, uu.state
  from (select u.id, u.user_login_name, u.employee_id, u.state
          from ims_ot_user u
         where exists (select eo.employee_id
                  from ims_rt_employee_organization eo
                 where exists (select *
                          from (select ro.super_organization_id
                                  from ims_rt_organization ro
                                 where ro.organization_id = '8a847c0b55ca7b730155cad5cd50001d') org1
                         where org1.super_organization_id =
                               eo.organization_id)
                   and eo.employee_id = u.employee_id)) uu
  left join ims_ot_employee ee
    on uu.employee_id = ee.id

 

 

19:29:05.311 [main] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 6 mappings in <unknown> 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable. 19:29:05.314 [main] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.engine.ConfigurationImpl - Setting custom MessageInterpolator of type org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.engine.ConfigurationImpl - Setting custom ParameterNameProvider of type org.springframework.validation.beanvalidation.LocalValidatorFactoryBean$1 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration. 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader 19:29:05.314 [main] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only. 19:29:05.317 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator as ValidatorFactory-scoped message interpolator. 19:29:05.317 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver. 19:29:05.317 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider. 19:29:05.317 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider. 19:29:05.317 [main] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory. 19:29:05.317 [main] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice 19:29:05.318 [main] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice 19:29:05.318 [main] INFO org.springframework.mock.web.MockServletContext - Initializing Spring TestDispatcherServlet '' 19:29:05.318 [main] INFO org.springframework.test.web.servlet.TestDispatcherServlet - Initializing Servlet '' 19:29:05.318 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected AcceptHeaderLocaleResolver 19:29:05.318 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected FixedThemeResolver 19:29:05.319 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@5ac7aa18 19:29:05.319 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected org.springframework.web.servlet.support.SessionFlashMapManager@4cdd2c73 19:29:05.319 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data 19:29:05.319 [main] INFO org.springframework.test.web.servlet.TestDispatcherServlet - Completed initialization in 1 ms 19:29:05.321 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - POST "/user/login", parameters={} 19:29:05.321 [main] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public com.tplink.nbu.demo.basicspringboot.dto.UserLoginSuccessDTO com.tplink.nbu.demo.basicspringboot.controller.UserLogInOutController.login(com.tplink.nbu.demo.basicspringboot.dto.UserLoginDTO) 19:29:05.322 [main] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Read "application/json" to [com.tplink.nbu.demo.basicspringboot.dto.UserLoginDTO@4abf3f0] 19:29:05.324 [main] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolved [com.tplink.nbu.demo.basicspringboot.exception.UnauthorizedException] 19:29:05.324 [main] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Completed 401 UNAUTHORIZED java.lang.AssertionError: Status 预期:200 实际:401 <点击以查看差异> at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59) at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:98) at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:619) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:196) at com.tplink.nbu.demo.basicspringboot.controller.UserLogInOutControllerTest.testLogin_Success(UserLogInOutControllerTest.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:54) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:99) at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:105) at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:40) at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值