web-dev-qa-db-ja.com

NonUniqueDiscoveredSqlAliasException:ネイティブSQLクエリの自動検出中に重複したSQLエイリアス[ASC_ID]が発生しました

3つのテーブルがありますCREDENTIAL_USERCREDENTIAL_EXPIRATIONおよびASC_DETAILS-次のようなもの:

CREDENTIAL_USER { ASC_ID, name, ITEM}CREDENTIAL_USER { MONTH, YEAR, ASC_ID}およびASC_DETAILS {ASCID, NAME, ROLE}.

単純なネイティブSQL結合を実行して、CREDENTIAL_USER.ASC_IDおよびASC_DETAAILS.ASCIDのみを次のように選択しました。

Query query = entityManager.createNativeQuery("SELECT ad.ASCID,ad.NAME,ad.CRED_EMPLOYEE_FNAME,ad.CRED_EMPLOYEE_LNAME,ad.CRED_EMPLOYEE_EMAIL,ad.CRED_EMPLOYEE_REMINDER,"+
                              " cu.*, ce.*, cl.* FROM ASC_DETAILS ad,CREDENTIAL_USER cu, CREDENTIAL_EXPIRATION ce, CREDENTIAL_LICENSE cl WHERE"+ 
                              " cu.IS_CRD_EMPLOYEE = true AND cl.IS_EMPLOYEE = true AND  ce.LICENSE_ID = cl.LICENSE_ID  AND cu.ASC_ID=ad.ASCID"+ 
                              " AND ce.LICENSE_EXP_YR >= "+year+" AND (ce.IS_LICENSE_YES=1 OR ce.IS_LICENSE_YES=3) AND cu.ASC_ID=ce.ASC_ID AND"+
                              " cu.ID=ce.EMPLOYEE_ID");
             List<Object[]> list = query.getResultList();

ローカルで問題なく実行されていますが、org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [ASC_ID] during auto-discovery of a native-sql query

JBossサーバーでの例外

スタックトレース:

23:30:00,300 ERROR [stderr] (pool-10-thread-1) javax.persistence.PersistenceException: org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [ASC_ID] during auto-discovery of a native-sql query
23:30:00,301 ERROR [stderr] (pool-10-thread-1)  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.Java:1361)
23:30:00,302 ERROR [stderr] (pool-10-thread-1)  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.Java:1289)
23:30:00,303 ERROR [stderr] (pool-10-thread-1)  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.Java:261)
23:30:00,303 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
23:30:00,304 ERROR [stderr] (pool-10-thread-1)  at  Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
23:30:00,304 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
23:30:00,305 ERROR [stderr] (pool-10-thread-1)  at Java.lang.reflect.Method.invoke(Method.Java:616)
23:30:00,305 ERROR [stderr] (pool-10-thread-1)  at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.Java:310)
23:30:00,306 ERROR [stderr] (pool-10-thread-1)  at Sun.proxy.$Proxy42.getResultList(Unknown Source)
 23:30:00,307 ERROR [stderr] (pool-10-thread-1)  at com.asc.dao.UserDAO.getPendingNotificationCredEmployee(UserDAO.Java:991)
23:30:00,307 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
23:30:00,308 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
23:30:00,308 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
23:30:00,309 ERROR [stderr] (pool-10-thread-1)  at Java.lang.reflect.Method.invoke(Method.Java:616)
23:30:00,309 ERROR [stderr] (pool-10-thread-1)  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.Java:309)
23:30:00,310 ERROR [stderr] (pool-10-thread-1)  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.Java:196)
23:30:00,311 ERROR [stderr] (pool-10-thread-1)  at Sun.proxy.$Proxy34.getPendingNotificationCredEmployee(Unknown Source)
23:30:00,311 ERROR [stderr] (pool-10-thread-1)  at com.asc.service.UserService.getPendingNotificationCredEmployee(UserService.Java:2661)
23:30:00,312 ERROR [stderr] (pool-10-thread-1)  at com.asc.service.UserService$$FastClassByCGLIB$$de8fbe27.invoke(<generated>)
23:30:00,312 ERROR [stderr] (pool-10-thread-1)  at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.Java:204)
23:30:00,313 ERROR [stderr] (pool-10-thread-1)  at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.Java:617)
23:30:00,314 ERROR [stderr] (pool-10-thread-1)  at com.asc.service.UserService$$EnhancerByCGLIB$$d2e7fa8d.getPendingNotificationCredEmployee(<generated>)
23:30:00,314 ERROR [stderr] (pool-10-thread-1)  at com.asc.service.ExpirationNotificationService.sendAlertToAdmin(ExpirationNotificationService.Java:47)
23:30:00,315 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
23:30:00,316 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
23:30:00,316 ERROR [stderr] (pool-10-thread-1)  at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
23:30:00,317 ERROR [stderr] (pool-10-thread-1)  at Java.lang.reflect.Method.invoke(Method.Java:616)
23:30:00,317 ERROR [stderr] (pool-10-thread-1)  at org.springframework.util.MethodInvoker.invoke(MethodInvoker.Java:273)
23:30:00,318 ERROR [stderr] (pool-10-thread-1)  at org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.Java:65)
23:30:00,318 ERROR [stderr] (pool-10-thread-1)  at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.Java:51)
23:30:00,319 ERROR [stderr] (pool-10-thread-1)  at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.Java:81)
23:30:00,320 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:471)
23:30:00,320 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.Java:334)
23:30:00,321 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.FutureTask.run(FutureTask.Java:166)
23:30:00,321 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.Java:165)
23:30:00,322 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.Java:266)
23:30:00,323 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1146)
23:30:00,323 ERROR [stderr] (pool-10-thread-1)  at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
23:30:00,324 ERROR [stderr] (pool-10-thread-1)  at Java.lang.Thread.run(Thread.Java:679)
23:30:00,325 ERROR [stderr] (pool-10-thread-1) Caused by: org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [ASC_ID] during auto-discovery of a native-sql query
23:30:00,326 ERROR [stderr] (pool-10-thread-1)  at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.Java:594)
17
Avinash

CREDENTIAL_USER {ASC_ID、名前、ITEM}、CREDENTIAL_USER {MONTH、YEAR、ASC_ID}の両方にASC_IDが含まれているため、選択クエリでASC_IDがあいまいになります。データ列を賢明に選択し、各列に個別のエイリアスを指定します

30
Ashish Mohan

初めて合体を使用するとき、私もこの問題に遭遇します。私は書いてそれを解決しました:

...
coalesce(column_name, 'default_value')as key_Word,
...

私のクエリで。 Coalesce(column_name、 'default_value')を追加すると、coalesceという名前の値がいくつか作成され、このエラーが発生します。これが私のような人に役立つことを願っています。

1
Khasan 24-7