guys thans for time and help
i have HQL Query using case and paramater and i get a error when i set the parameters
my query is:
SELECT
IC.Sources,
IC.Total,
IC.Destination,
IC.Where,
ICP.Date,
ICP.filedirectory,
ICP.filename
FROM IcmA AS IC, IcmProc AS ICP
WHERE IC.uniqueid = ICP.uniqueid
AND IC.Sources = :Num OR IC.Destination= :Num
AND CASE
WHEN LENGTH(IC.Sources) = 1 OR LENGTH(IC.Destination) = 1 THEN
:NBalance
WHEN LENGTH(IC.Sources) > 1 OR LENGTH(IC.Destination) > 1 THEN
:NBalance
ELSE
:NBalance
END = :NBalance
AND(DATE_FORMAT(ICP.Date, '%Y/%m/%d') >= :fDate AND DATE_FORMAT(ICP.Date, '%Y/%m/%d') <= :tDate) ORDER BY ICP.Date DESC
Error:
org.hibernate.hql.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.ast.tree.SelectExpression>
java.lang.ClassCastException: org.hibernate.hql.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.ast.tree.SelectExpression
Related
Hi guys I have a problem with SPEL - Flexible Search, this is my error log when into my entity I click on button search:
ERROR [hybrisHTTP6] [PagingDelegateController] cannot search unknown field 'TableField(name='inStockStatus',langPK='null',type=Product)' within type Product unless you disable checking
and this is the query that I must create :
select {p.code},{p.description},{bs.uid}, (CASE WHEN ({p.onlineDate} is not null AND {p.onlineDate} > current_timestamp ) THEN 1 else 0 END)
from {Product as p join StockLevel as s on {s.productCode} = {p.code} join BaseStore2WarehouseRel as b on {b.target} = {s.warehouse} join BaseStore as bs on {bs.pk} = {b.source}}
where {bs.uid} in ('baseStorePk')
and {p.code} = '?productCode'
and {p.description} = '?description'
and {p.descriptionCics} = '?descriptionCics'
and {p.onlinedate} <= '?onlineDateFrom'
and {p.onlinedate} >= '?onlineDateTo'
and {s.inStockStatus} = '?inStockStatus'
and {p.doneBy} = '?doneBy'
and {s.outOfStockCause} = '?oosCause'
and {p.department} = '?department'
and {p.grm} = '?grm'
and in the image the report that I have create into myExtension-items-core.xml
based on Exception it's clear you are referring wrong attribute of product is "inStockStatus".
please replace with {s.inStockStatus} instead of {p.inStockStatus}
I'm using Java 11 and Postgres 9.6. I am writing a SQL query that will be included in my Java application and I will pass in values to the variables designated with a:
SQL
CASE
WHEN (:designatorInclude IS NOT NULL)
THEN totdl.designator_id IN (:designatorInclude)
ELSE ttl.product_code IS NOT NULL
END
Java
String filterProductCodes = IOUtil.readResourceText(MyService.class, "sql_files/FilterProductCodes.sql");
Query filterProductCodesQuery = this.em.createNativeQuery(filterProductCodes)
if(inDto.getIdList() != null)
{
filterProductCodesQuery.setParameter("designatorInclude", inDto.getIdList);
}else{
filterProductCodesQuery.setParameter("designatorInclude", null);
}
Passing variables in like this works in many other places in the application. The difference here is that I'm using a CASE/WHERE statement.
Everything compiles fine, but when I try to hit this part of the code, I get the following error:
PSQLException: ERROR: argument of CASE/WHEN must be type boolean, not type record
I found 1 post on the internet about this and it did not apply to my situation.
Can anyone shed some light on this? Any suggestions on how I can get this to work?
Full SQL - case statement is towards the end.
SELECT DISTINCT ttl.product_code,
si.condition,
totdl.designator_id,
ttl.active as ttl_active,
l.active as l_active,
ii.mls_order_id,
ii.damaged,
ttl.id as ttl_id,
ll.location_id as ll_locationId,
cl.location_id as cl_locationId
FROM serial_item si
JOIN inventory_item ii ON ii.id = si.id
AND ii.mls_order_id IS NULL
AND ii.damaged = false
JOIN title ttl ON ttl.id = si.title_id
AND ttl.active = true
JOIN public.title_owner_title_designator_lookup totdl ON ttl.id = totdl.title_id
JOIN locator l ON l.id = ii.locator_id
AND l.active = true
LEFT JOIN location_locator ll ON ll.id = l.id
AND ll.status IN ('Shelf', 'Intake', 'Donation', 'Wholesaler')
LEFT JOIN course_locator cl ON cl.id = l.id
WHERE COALESCE(ll.location_id, cl.location_id) = :locationId
AND ll.do_not_list_on_markets = false
AND CASE
WHEN (:designatorInclude IS NOT NULL)
THEN totdl.designator_id IN (:designatorInclude)
ELSE ttl.product_code IS NOT NULL
END
I got this to work by changing my IS NOT NULL check to a COALESCE
CASE
WHEN **(COALESCE(:include, 0) != 0)**
THEN totdl.designator_id IN (:include)
ELSE ttl.product_code IS NOT NULL
If I would you, I would select just row column such
SELECT ttl.product_code, totdl.designator_id
FROM ...
I mapped this query normal to an Bean or Entity.
And an transient getter could solve your problem.
Hi I am using the below query to retrieve a list of products.
select qphgr.XPRODHRCHYGRP,qphgr.CPRODHRCHYGRP ,qphgr.CBUSN,qphgr.CSGM
from HPP.PNIGUT pnigu
,HPP.POGSRT pogsr
, HQL.QPHGRT qphgr
,HQL.QPRODT qprodt
,HPP.PGPLUT pgplu
where pogsr.CBUSN = '30'
and pogsr.CSGM IN ('CBU')
and pogsr.CORG = '25K'
and pogsr.CSUPPL = '999'
and pogsr.CRELT = 'NIG'
and pnigu.DVERSN between pogsr.DFR and pogsr.DTO
and pnigu.CBUSN = pogsr.CBUSN_REL
and pnigu.CSGM = pogsr.CSGM_REL
and pnigu.CORG = pogsr.CORG_REL
and pnigu.CSUPPL = pogsr.CSUPPL_REL
and pnigu.CBUSN = qphgr.CBUSN
and pgplu.cmod = qprodt.cmod
and pgplu.CTYP = qprodt.CTYP
and pgplu.copt = qprodt.copt
and pgplu.CHECOL = qprodt.CHECOL
and qprodt.CACTIV= 'Y'
and qprodt.CBUSN = qphgr.CBUSN
and qprodt.CSGM = qphgr.CSGM
and qprodt.CPRODHRCHYGRP = qphgr.CPRODHRCHYGRP
and pnigu.CORG=pgplu.CORG
and pnigu.CSUPPL=qprodt.CSUPPLGEN
group by qphgr.XPRODHRCHYGRP,qphgr.CPRODHRCHYGRP,qphgr.CBUSN,qphgr.CSGM,qphgr.NPRNTINGSEQPP
order by qphgr.NPRNTINGSEQPP
When I run this query in Squirrel it returns 15 rows which is right. But when I'm executing the same query from inside the application (I have used hibernate) it is returning only 14 rows in the return list! How is that possible. What's going wrong?
Query is getting executed well but problm with JPA .Please help me to find the wrongness.
Query works well if I execute seperately in Oracle SQL client but with application gives error.
Am getting exception in this line as Eclipse says
return genDODetails(pSess.executeQuery(rq));
Query :
SELECT DOD.ID AS DODID,ORDD.ID AS ORDDID,DOD.SHIPQTY AS DOQTY,DOD.BUYERCODE AS BUYERCODE,DOD.BUYERPARTNUM AS BUYERPARTNUM,
DOD.BUYERPARTDESC AS BUYERPARTDESC,DOD.LINENUM AS DOLINENUM,DOD.LINEREVNUM AS LINEREVNUM,
DOD.LINEINDICATIOR AS LINEINDICATOR,DOD.ORDLINENUM AS ORDLINENUM,ORDD.SHIPQTY AS SHIPPEDQTY,
DOD.RSPREMARK1 AS SUPREMARK,DOD.ORDNUM AS PONUM
FROM RDT_DELIVERYORDERDETAIL DOD,RDT_ORDERDETAIL ORDD ,RDT_ORDER ORDM
WHERE ORDD.LATEST =1
AND ORDM.LATEST =1
AND ORDM.ID = ORDD.ORDID
AND ORDD.RESPSTR1 ='EP'
AND ORDD.LINENUM = DOD.ORDLINENUM
AND ORDM.DOCNUM = DOD.ORDNUM
AND DOD.LATEST =1
AND CONTROLLERID =(SELECT ID FROM RDT_ORGANIZATION WHERE OUCODE ='yes' AND PARENTID IS NULL)
AND DOD.DOID = 72
ORDER BY DODID DESC;
JPA Execution Code:
public List<DODetail> getDODetails(Map<String,Object> hparams) throws Exception
{
String sqlQuery= pSess.getSQLString4NamedQuery("DO_VIEW_DETAIL");
String doid = hparams.get("DOID")!=null ?(String)hparams.get("DOID"):"";
Hashtable<String,Object> dbparams=new Hashtable();
dbparams.put(":DOID",doid);
sqlQuery = (String)pSess.getParamQuery(sqlQuery, dbparams);
ReportQuery rq=new ReportQuery();
rq.setReferenceClass(DODetail.class);
rq.addAttribute("DODID");
rq.addAttribute("ORDDID");
rq.addAttribute("DOQTY");
rq.addAttribute("BUYERCODE");
rq.addAttribute("BUYERPARTNUM");
rq.addAttribute("BUYERPARTDESC");
rq.addAttribute("DOLINENUM");
rq.addAttribute("LINEREVNUM");
rq.addAttribute("LINEINDICATOR");
rq.addAttribute("ORDLINENUM");
rq.addAttribute("SHIPPEDQTY");
rq.addAttribute("SUPREMARK");
rq.addAttribute("PONUM");
rq.setSQLString(sqlQuery);
return genDODetails(pSess.executeQuery(rq));
}
private List<DODetail> genDODetails(Object obj)throws Exception
{
if(obj==null ) return null;
List newList = (List)obj;
Iterator it = newList.iterator();
List<DODetail> doDetails = new ArrayList<DODetail>();
while(it.hasNext())
{
ReportQueryResult rs=(ReportQueryResult)it.next();
DODetail order=new DODetail();
order.setId(rs.get("DODID")!=null?((BigDecimal)rs.get("DODID")).longValue():new Long(0));
order.setRefid(rs.get("ORDDID")!=null?((BigDecimal)rs.get("ORDDID")).longValue():new Long(0));
order.setShipqty(rs.get("DOQTY")!=null?(BigDecimal)rs.get("DOQTY"):new BigDecimal(0));
order.setBuyercode(rs.get("BUYERCODE")!=null?(String)rs.get("BUYERCODE"):"");
order.setBuyerpartnum(rs.get("BUYERPARTNUM")!=null?(String)rs.get("BUYERPARTNUM"):"");
order.setCategory(rs.get("BUYERPARTDESC")!=null?(String)rs.get("BUYERPARTDESC"):"");
order.setLinenum(rs.get("DOLINENUM")!=null?((BigDecimal)rs.get("DOLINENUM")).longValue():new Long(0));
order.setLinerevnum(rs.get("LINEREVNUM")!=null?(String)rs.get("LINEREVNUM"):"");
order.setLineindicator(rs.get("LINEINDICATOR")!=null?(String)rs.get("LINEINDICATOR"):"");
order.setOrdlinenum(rs.get("ORDLINENUM")!=null?((BigDecimal)rs.get("ORDLINENUM")).toPlainString():"");
order.setAssignqty(rs.get("SHIPPEDQTY")!=null?(BigDecimal)rs.get("SHIPPEDQTY"):new BigDecimal(0));
order.setRspremark1(rs.get("SUPREMARK")!=null?(String)rs.get("SUPREMARK"):"");
order.setOrdnum(rs.get("PONUM")!=null?(String)rs.get("PONUM"):"");
doDetails.add(order);
}
return doDetails;
}
Make sure, you didnt have a trailing semicolon in your query string, before execution.
Because, it is not needed, and it is one of the possible reasons for this error.
It is not required , when you send a query to the database using a OCI driver. Only when manually executing in SQL*Plus or something needs that as pushing the sql to the database engine for execution.
I have a query which updates (table1) and inserts into (table2) and returns a list of ids at the end which have been updated by the query.
When I run it from sql it runs properly.
But when I run from my code it returns the affected ids but it does not update & the rows.
Is it because I am doing it as: namedQuery.list() ??
SQL Query:
step 1: create table variable
step 2: update table1
step 3: store "Output Into" table variable; insert table variable content into table2
step 4: retrun affected rows (table variable column)
Here's the sql:
Declare #tempHistoryTable Table(
AG_TASK_ID int,Fulfillment_Request_ID int,Task_Type_ID int,Task_Status varchar(25)
,CF_System_User_ID int,Modified_By_System_User_ID int,AG_Task_Date datetime,row_version int
)
Declare #infoNeeded int,
#reviewResult int,
#researcherClass varchar(20),
#infoNeededReview int;
Update ag_task Set task_status = case when task_status = 'awaitingHitEntry' or task_status = 'Uploaded'
then task_status when (data_source = 'New_Jersey' or data_source = 'Illinois') and :action = 'Assign'
then 'sentForProcessing' else 'New' end
,db_version = case when db_version is null then 0 else db_version + 1 end
,modified_by_system_user_id = :assignedBy
,system_user_id = :assigningTo
,bpm_version = db_version
,task_type_id = case when task_type_id = #infoNeeded and :action = 'Assign'
then #reviewResult
when task_type_id = #infoNeeded and #researcherClass != 'External'
then #reviewResult
when (task_type_id = #infoNeededReview or task_type_id = #reviewResult) and #researcherClass = 'External'
then #infoNeeded
else task_type_id end
,creation_date = case when (task_type_id = #infoNeededReview or task_type_id = #reviewResult) and #researcherClass = 'External'
then getDate() else creation_date end
,task_assigned_date = case when :assigningTo is null then null else GETDATE() end
Output inserted.ag_task_id,inserted.Fulfillment_Request_ID,inserted.Task_Type_ID
,inserted.Task_Status,inserted.system_user_id
,inserted.Modified_By_System_User_ID,getdate(),inserted.row_version
Into #tempHistoryTable
Where fulfillment_request_id in (:fulfillmentRequestIds) and completion_date is null and
1 = case when data_source in ('New_Jersey', 'Illinois') and processing_date is null then 2 else 1 end
and 1 = case when :action = 'Claim' and system_user_id is not null then 2 else 1 end
and 1 = case when system_user_id is null and :assigningTo is null then 2 else 1 end
insert into AG_TASK_HISTORY (
AG_TASK_ID
,Fulfillment_Request_ID
,Task_Type_ID
,Task_Status
,CF_System_User_ID
,Modified_By_System_User_ID
,AG_Task_Date
,row_version
)
SELECT AG_TASK_ID
,Fulfillment_Request_ID
,Task_Type_ID
,Task_Status
,CF_System_User_ID
,Modified_By_System_User_ID
,AG_Task_Date
,row_version
from #tempHistoryTable
select Fulfillment_Request_ID from #tempHistoryTable
and this is how i'm calling the code:
String queryName = AgTask.class.getName () + ".claimAssignTasks";
final Query namedQuery = getNamedQuery ( queryName );
logger.debug("assigningTo: "+assigningTo);
logger.debug("assignedBy: "+assignedBy);
logger.debug("action: "+action);
logger.debug("fulfillmentRequestIdList: "+fulfillmentRequestIdList);
namedQuery.setParameterList("fulfillmentRequestIds", fulfillmentRequestIdList);
namedQuery.setParameter("assigningTo", assigningTo);
namedQuery.setParameter("assignedBy",assignedBy);
namedQuery.setParameter("action",action);
logger.debug("Query: "+namedQuery.getQueryString());
List<Integer> frIdList = new ArrayList<Integer>();
frIdList = namedQuery.list();
This is how i am running my test (which properly updates and inserts into table in my DB):
#Test
public void testclaimAssignTasks(){
transactionTemplate.execute(new TransactionCallbackWithoutResult ()
{
public void doInTransactionWithoutResult (TransactionStatus arg0)
{
Set<Integer> frIds = new HashSet<Integer>();
frIds.add(190195);
frIds.add(190257);
frIds.add(190243);
frIds.add(190205);
//java.util.List<Integer> frIdList =
java.util.List<Integer> frIdList = agTaskSearchDao.claimAssignTasks(frIds,846,846,"Reassign");
log.info("collection size: "+frIdList.size());
for(Integer fulfillmentRequestId : frIdList){
log.debug("fulfillmentRequestId: "+fulfillmentRequestId);
}
}
});
}
First off, I think putting such a complex query into the context of Hibernate/JPA is a really bad idea. If I were you I would try to analyze the sql and break it down, in order to see if this is something that could be solved much cleaner by lending from JPA/Hibernate functionality. Or maybe you'll end up scrapping the whole thing, solving the problem at hand with different methods.
That being said, if you want to execute an SQL (or HQL/JPQL) that is supposed to change the state of the database, you will need to use the method executeUpdate() of the Query interface, as opposed to list() or uniqueResult() that is used for retrieval of data only.