SQL Error: 102, SQLState: S0001 Incorrect syntax near '@P404'

Viewed 22

Context

I am trying to update the records of an MSSQL table using an automated scheduler, running in a Java Spring project. The product of calculations, performed on values stored in multiple array lists, are what I am trying to update to the database table.

Because calculations are performed on a large dataset, and to avoid the nasty 'Java Heap Space' error, I'm implementing paging.

Problem

Only 1 of 7 records gets updated before the application crashes and displays the error:

2022-09-20 11:36:53.611  WARN 24524 --- [   scheduling-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 102, SQLState: S0001
2022-09-20 11:36:53.611 ERROR 24524 --- [   scheduling-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Incorrect syntax near '@P404'.
2022-09-20 11:36:53.636 ERROR 24524 --- [   scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task

My problem is different from others in it's category because I am not implementing a custom SQL script. From research, I have gathered that '@P404' could be referring to a parameter position in the SQL script generated by hibernate.

Code Snippet

List<SalesDailyDto> sales = salesDaily.findSalesDaily(branchId, dates, deptIdsLong);                
List<PromotionSalesNew> promotions = promo.findByIdSalesDateInAndIdBranchIn(dates, branchId);                               
List<Long> items = promotions.stream().map(pm -> pm.getId().getItem()).collect(Collectors.toList());

promotions = null;                                                                          
ArrayList<SalesDaily> promoSales = new ArrayList<SalesDaily>(1000000);  

//Initializing Page Object
Page<SalesDaily> salesDailyPage;
int page = 0;

//Loop to batch items in batches of 1500 
for(int i = 0; i < items.size(); i = i + 1500)
{   
    ArrayList<Integer> itemBatch = new ArrayList<>();
    for (int x = i; x < (i + 1500); x++)
    {               
        if(x < items.size())
        {                       
            itemBatch.add(items.get(x).intValue());                         
            count++;
        }
    }
    
    do {
        //Populate page object with page size of 100 000
        salesDailyPage = salesDaily.findByIdSalesDateInAndIdBranchInAndIdItemInAndDepartmentIn(dates, branchId, itemBatch, deptIdsLong, PageRequest.of(page, 100000));
        //Add contents of page object to array list
        promoSales.addAll(salesDailyPage.getContent());
        page++;                     
    } 
    while(salesDailyPage.hasNext());            
}               
items = null;

if(!sales.isEmpty()) 
{                                   
    //Save to Database
    saveWeeklyBudgets(sales, dates, bLevel, promoSales);                                                        
    sales = null;
}
0 Answers
Related