Home Error during select from a sub-query with jpa
Reply: 0

Error during select from a sub-query with jpa

user8294
1#
user8294 Published in April 25, 2018, 6:16 pm


I've tried to get result on this code:

List<SfsRepDemNote> lis = new ArrayList<SfsRepDemNote>();
            String sql = "select * from ( "
                    + "SELECT"
                    + "    core.SFS_REP_DEM_NOTES_ID,"
                    + "    Rank( ) Over( partition by core.hkid,core.scheme_code,core.demand_note_type Order by core.issue_date desc) rnk "
                    + "FROM"
                    + "    sfs_rep_dem_notes core"
                    + "    "
                    + "WHERE"
                    + "    core.void_ind = 'N'"
                    + "    AND   core.hold_ind = 'N'"
                    + "    AND   trunc(grace_due_date) <= TO_DATE( :dat ,'dd/mm/yyyy')"
                    + "    AND   hkid = :hkid "
                    + "    AND   exists ("
                    + "        SELECT"
                    + "            1"
                    + "        FROM"
                    + "            sfs_rep_dem_note_components com "
                    + "            JOIN sfs_loan_infos loinf ON com.sfs_loan_info_id = loinf.sfs_loan_info_id "
                    + "        WHERE"
                    + "            loinf.loan_ref_num in :ref  "
                    + "            and   core.sfs_rep_dem_notes_id = com.sfs_rep_dem_notes_id"
                    + "            AND   nvl(com.surcharge_unpaid,0) + nvl(com.instal_interest_unpaid,0) + nvl(com.instal_principal_unpaid,0) >= 1"
                    + "    )) where rnk = 1";
            Query query = super.getEntityManager().createQuery(sql);
            query.setParameter("dat", "01/02/2018");// letterDefaultDateFormat.format(defermentCase.getReceiveDate()));
            query.setParameter("hkid", "E80001");// defermentCase.getGaHkid());
            query.setParameter("ref", selectedValues);
            //logger.info(query.getParameterValue(3));

            List<Object[]> list = query.getResultList();
            logger.info("list =" + list.size());
            for (Object[] array : list) {
                //logger.info("id = " + array[0].toString());
                lis.add(findByPK(Long.parseLong(array[0].toString()),
                        SfsRepDemNote.class));
                // logger.info(tmpQuery.getResultList().size());
            }
            logger.info("end");
            return lis;

In some cases, I need to use "IN cause" on it. I've tried with createSelectNativeQuery() to get my result, but for the param :ref it can not be work on native Query, but in ejb ql I just got this error msg:

Exception Description: Syntax error parsing [select * from ( SELECT
core.SFS_REP_DEM_NOTES_ID, Rank( ) Over( partition by core.hkid,core.scheme_code,core.demand_note_type Order by core.issue_date desc) rnk from sfs_rep_dem_notes core where 2=2 and core.void_ind = 'N' AND core.hold_ind = 'N' AND
trunc(grace_due_date) <= TO_DATE( :dat ,'dd/mm/yyyy') AND hkid = :hkid AND exists ( SELECT 1 from
sfs_rep_dem_note_components com JOIN sfs_loan_infos loinf ON com.sfs_loan_info_id = loinf.sfs_loan_info_id WHERE
loinf.loan_ref_num in :ref and
core.sfs_rep_dem_notes_id = com.sfs_rep_dem_notes_id AND
nvl(com.surcharge_unpaid,0) + nvl(com.instal_interest_unpaid,0) + nvl(com.instal_principal_unpaid,0) >= 1 )) WHERE rnk = 1 ]. [125, 125] A select statement must have a FROM clause. [7, 7] The left expression is missing from the arithmetic expression. [9, 125] The right expression is not an arithmetic expression. [154, 799] The query contains a malformed ending. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605) at hksarg.wfsfaa.isfast2.framework.jpa.WrappedEntityManager.createQuery(WrappedEntityManager.java:92) at hksarg.wfsfaa.isfast2.framework.jpa.SecuredEntityManager.getSecuredJpql(SecuredEntityManager.java:594) at hksarg.wfsfaa.isfast2.framework.jpa.SecuredEntityManager.createQuery(SecuredEntityManager.java:126) at hksarg.wfsfaa.isfast2.ejb.deferment.DefermentLetterUtilBean.getSFSOverdueDemandNote(DefermentLetterUtilBean.java:882) at hksarg.wfsfaa.isfast2.ejb.deferment.DefermentLetterUtilBean.getAdditionalInfoLetterContent(DefermentLetterUtilBean.java:419) at hksarg.wfsfaa.isfast2.ejb.deferment.DefermentLetterUtilBean.test(DefermentLetterUtilBean.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) at hksarg.wfsfaa.isfast2.framework.ejb.BaseBean.methodInterceptor(BaseBean.java:104) at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:89) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) at net.bull.javamelody.MonitoringInterceptor.intercept(MonitoringInterceptor.java:72) at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:89) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:272) ... 136 more

I've tired on it, can everybody can give me some advice? thx for help

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.260933 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO