gpt4 book ai didi

java - 使用 jpa 从子查询中选择时出错

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:57 25 4
gpt4 key购买 nike


我试图通过这段代码获得结果:

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 Cause”。我尝试使用 createSelectNativeQuery() 来获取结果,但对于参数 :ref 它不能在 native 查询上工作,但在 ejb ql 中我刚刚收到此错误消息:

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

我已经厌倦了,大家可以给我一些建议吗?感谢帮助

最佳答案

只需将 Query query = super.getEntityManager().createQuery(sql); 替换为 Query query = super.getEntityManager().createNativeQuery(sql); 假设您使用的是纯 jpa 实现。另外,将 native 查询 IN 部分从 loinf.loan_ref_num in :ref 编辑为 loinf.loan_ref_num in (:ref)

关于java - 使用 jpa 从子查询中选择时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49808601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com