How resolve "unknown field 'TableField' - java

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}

Related

CASE WHEN on a passed in variable

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.

Delete range not working - Google Sheets API - Swift

I am working on a view controller where the user should delete a row of a sheet within a spreadsheet which is located in google drive.
Once the user has successfully logged in, a table view is displayed and the user can delete the row by swiping left on the appropriate cell. The code below shows the deletion process. When I trigger the process, the following error is displayed:
"Invalid requests[0].deleteRange: No grid with id: 0"
//Delete Function TableView - Access by swiping left.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
//1 - Delete Row From Index
let toDelete = GTLRSheets_DeleteRangeRequest.init()
toDelete.range?.sheetId = 317088521
toDelete.range?.startRowIndex = 6
toDelete.range?.endRowIndex = 6
toDelete.range?.startColumnIndex = 0
toDelete.range?.endColumnIndex = 3
toDelete.shiftDimension = "ROWS"
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
let request = GTLRSheets_Request.init()
request.deleteRange = toDelete
batchUpdate.requests = [request]
let deleteQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetID)
service.executeQuery(deleteQuery, delegate: self, didFinish: #selector(deleteFromIndexWithTicket(ticket:finishedWithObject:error:)))
}
func deleteFromIndexWithTicket(ticket: GTLRServiceTicket, finishedWithObject result : GTLRSheets_BatchGetValuesResponse , error : NSError?) {
if let error = error {
print(error.localizedDescription)
return
}
print("Deleted from index")
}
My bad... I had not initialised the GridRange. Below is the working code.
//1 - Delete Row From Index
let toDelete = GTLRSheets_DeleteRangeRequest.init()
let gridRange = GTLRSheets_GridRange.init()
toDelete.range = gridRange
gridRange.sheetId = indexID as NSNumber
gridRange.startRowIndex = lengthTrainingDatabase - indexPath.row as NSNumber
gridRange.endRowIndex = lengthTrainingDatabase - indexPath.row + 1 as NSNumber
toDelete.shiftDimension = kGTLRSheets_DeleteRangeRequest_ShiftDimension_Rows

my SQL query returns 15 rows but while running via hibernate it return 14 rows to the list?

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?

How to create use CASE statement inside WHERE using parameters in HQL?

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

Update and return list from hibernate (using sql query)

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.

Categories