myBatis: ### Error querying database. Cause: java.lang.UnsupportedOperationException - spring-boot

I stuck in a problem with following while using myBatis.
2022-06-28 18:31:18,906 DEBUG [task-2 ]
c.b.c.r.StoreDAO : ###### params StoreSearchParam(uid=null,
latitude=127.044093, longitude=37.5025597, service_group_list=[4, 2],
serviceGroupList=[4, 2], store_class_id=null, page=1, num_per_page=10,
keyword=null, sort=distance, withLike=false)
2022-06-28 18:31:18,911 ERROR [http-nio-7000-exec-4 ] c.b.c.e.ExceptionResolver: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.UnsupportedOperationException
Cause: java.lang.UnsupportedOperationException org.mybatis.spring.MyBatisSystemException: nested exception is
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.UnsupportedOperationException
Cause: java.lang.UnsupportedOperationException at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy101.selectList(Unknown Source) at
org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.bullsone.car.repository.StoreDAO.storeList2(StoreDAO.java:238)
at
com.bullsone.car.repository.StoreDAO$$FastClassBySpringCGLIB$$38eb11a0.invoke()
at
org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at
com.bullsone.car.repository.StoreDAO$$EnhancerBySpringCGLIB$$395cd5c.storeList2()
at
com.bullsone.car.service.StoreService.searchStoreList(StoreService.java:316)
at
com.bullsone.car.service.StoreService$$FastClassBySpringCGLIB$$2fb3e42.invoke()
at
org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
at
com.bullsone.car.service.StoreService$$EnhancerBySpringCGLIB$$4fae4882.searchStoreList()
at
com.bullsone.car.controller.StoreController.lambda$searchStoreList$25(StoreController.java:760)
at
org.springframework.web.context.request.async.WebAsyncManager.lambda$startCallableProcessing$4(WebAsyncManager.java:337)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748) Caused by:
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.UnsupportedOperationException
Cause: java.lang.UnsupportedOperationException at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
... 25 common frames omitted Caused by:
java.lang.UnsupportedOperationException: null at
org.apache.ibatis.reflection.wrapper.CollectionWrapper.get(CollectionWrapper.java:38)
at
org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at
org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:119)
at
org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at
org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:88)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
... 32 common frames omitted
Here's my SQL statement.
The serviceGroupList is defined as List<Integer> there's no problem when all dynamic query removed related with serviceGroupList.
It seems to having problem(s) with foreach or serviceGroupList.size. But I don't know what I missed.
<select id="storeList2" parameterType="storeSearchParam" resultType="Store">
SELECT
MAS.NAME as SIDO_NAME,
M.NAME as SIGUNGU_NAME,
MSC.STORE_CLASS_ID, STORE_CLASS_NAME, STORE_CLASS_VALUE,
ROUND( 6371000 * acos( cos( radians(#{latitude}) ) * cos( radians(TS.LATITUDE ) )
* cos( radians(TS.LONGITUDE) - radians(#{longitude})) + sin(radians(#{latitude}))
* sin( radians(TS.LATITUDE)))) AS DISTANCE,
STORE_ID, STORE_NAME, STORE_DESCRIPTION, SIDO_CODE, SIGUNGU_CODE, ADDRESS, PHONE_NUMBER,
LATITUDE, LONGITUDE, WEEK_WORKTIME, WEEKEND_WORKTIME, HOLIDAY,
OPEN_MON, OPEN_TUE, OPEN_WED, OPEN_THU, OPEN_FRI, OPEN_SAT, OPEN_SUN, MON_OPEN_HR, MON_CLOSE_HR, TUE_OPEN_HR, TUE_CLOSE_HR, WED_OPEN_HR, WED_CLOSE_HR, THU_OPEN_HR, THU_CLOSE_HR, FRI_OPEN_HR, FRI_CLOSE_HR, SAT_OPEN_HR, SAT_CLOSE_HR, SUN_OPEN_HR, SUN_CLOSE_HR,
ALLOW_RESERVATION
FROM T_STORE TS
JOIN M_STORE_CLASS MSC ON TS.STORE_CLASS_ID = MSC.STORE_CLASS_ID
LEFT JOIN M_AREA_SIDO MAS ON TS.SIDO_CODE = MAS.CODE
LEFT JOIN M_AREA_SIGUNGU M on TS.SIGUNGU_CODE = M.CODE
WHERE TS.USE_YN = TRUE
<if test="serviceGroupList.size gt 0">
AND STORE_ID IN (
SELECT STORE_ID
FROM (
SELECT STORE_ID, SERVICE_GROUP_ID
FROM T_STORE_SERVICE TSS
JOIN T_CAR_SERVICE TCS on TCS.SERVICE_ID = TSS.SERVICE_ID
WHERE TCS.USE_YN = TRUE
AND TSS.USE_YN = TRUE
<foreach collection="serviceGroupList" item="item" index="index" separator="," open="AND SERVICE_GROUP_ID IN (" close=")">
#{item.value}
</foreach>
GROUP BY STORE_ID, SERVICE_GROUP_ID
) SG
GROUP BY STORE_ID
HAVING COUNT(SERVICE_GROUP_ID) = #{serviceGroupList.size}
)
</if>
<if test="keyword neq null and keyword neq ''">
AND (
STORE_NAME LIKE #{keyword}
OR MAS.NAME LIKE #{keyword}
OR M.NAME LIKE #{keyword}
)
</if>
<choose>
<when test="sort neq null and sort eq 'distance'">
ORDER BY DISTANCE
</when>
<otherwise>
ORDER BY STORE_NAME
</otherwise>
</choose>
<if test="num_per_page > 0">
LIMIT #{num_per_page} OFFSET #{offset}
</if>
</select>
This is for ParameterType class.
#Alias("storeSearchParam")
#Data #Getter #Setter
public static class StoreSearchParam {
public StoreSearchParam (Integer num_per_page, Integer page,
Double latitude, Double longitude,
Integer store_class_id,
List<Integer> service_group_list,
String keyword, String sort, Integer uid) {
this.num_per_page = num_per_page;
this.page = page;
this.latitude = latitude;
this.longitude = longitude;
this.store_class_id = store_class_id;
if (service_group_list == null) {
this.service_group_list = new ArrayList<>();
} else {
this.service_group_list = service_group_list;
}
this.serviceGroupList = new ArrayList<>(this.service_group_list);
this.keyword = keyword;
if (sort == null || sort.equals("name")) {
this.sort = "name";
} else {
this.sort = "distance";
}
this.uid = uid;
}
Integer uid;
Double latitude;
Double longitude;
List<Integer> service_group_list;
List<Integer> serviceGroupList;
Integer store_class_id;
Integer page;
Integer num_per_page;
String keyword;
String sort;
public Integer getOffset() {
return (page-1) * num_per_page;
}
boolean withLike = false;
}
...
Thank you for your help.

Related

java.io.FileNotFoundException:<file_path>/<file_name>(No such file or directory)

This is a spring batch application and I am trying to put values in an excel sheet but it is failing in creating the file.
I have a code, where I am using a writer to write data into an excel sheet, but after writing also, this error comes up:
java.io.FileNotFoundException:
<path_name>/AJI.xls (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy102.write(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:188)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:154)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:287)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:212)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:203)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:275)
at java.lang.Thread.run(Thread.java:748)
Writer Code:
#Override
public void write(List<? extends DialogTelekom> list) throws Exception {
/*FILE_NAME + ApplicationConstants.MULTICHOICE_FILE_START_NAME +
ApplicationConstants.UNDERSCORE +
LocalDate.now().plusDays(Long.parseLong(startDayOffset)).toString().replaceAll("-","")+ */
outputFilename = FILE_NAME+"AJI" + ".xls";
List<Samples> sortedDialogs = new ArrayList<>();
if (list.size() > 0) {
for (Object items : list) {
for (Samples myDialog : (List<Samples>) items) {
sortedDialogs.add(myDialog);
}
}
}
writeToExcel(outputFilename, sortedDialogs);
}
private void writeToExcel(String outputFilename , List<Samples> Sample)/* , String chCode*/ throws IOException {
workbook = new XSSFWorkbook();
currRow = 0;
// sheet = workbook.createSheet("Channel" + item.getId());
sheet = workbook.createSheet("AJI");
//sheet.createFreezePane(0, 3, 0, 3);
sheet.setDefaultColumnWidth(20);
initDataStyle();
Row topRow = sheet.createRow(currRow);
//TODO:
sheet=workbook.getSheet("AJI");
System.out.println(Sample.size());
System.out.println(Sample.toString());
currRow++;
addHeaders(sheet, HEADERSProgram, currRow);
for(Samples mySample : Sample){
Row programRow = sheet.createRow(currRow);
// TIME
createStringCell(programRow, Sample.getTime().toString(), 0);
// TITLE
createStringCell(programRow, Sample.getTitle(), 1);
// DURATION
createNumericCell(programRow, Sample.getDuration() != null ? Long.valueOf(Sample.getDuration()) : null, 2);
// EPISODE TITLE
createStringCell(programRow, Sample.getEpisode_Title() != null ? Sample.getEpisode_Title():null, 3);
// SYNOPSIS
createStringCell(programRow, Sample.getSnyopsis() != null ? Sample.getSnyopsis():null, 4);
// CATEGORY
createStringCell(programRow, Sample.getCategory() != null ? Sample.getCategory() : null, 5);
// SYNOPSYS
createStringCell(programRow, Sample.getType(), 6);
// CONTENT
createStringCell(programRow, Sample.getContent(), 7);
currRow++;
}
FileOutputStream fos = new FileOutputStream(outputFilename);
workbook.write(fos);
fos.close();
}
I have checked with debugger, It shows the correct for all the variables, still it is not creating the file. Can u help?
The error is clear that the path is not found; the file is not where the path points. Looks like the path is "<path_name>/AJI.xls" which clearly is wrong since it contains angle brackets. Seems that FILE_PATH is "<path_name>". I don't know what FILE_PATH is supposed to be, but I can say that you need to set FILE_PATH to the file's directory path ... not the string "<path_name>"
This is related to filepath and not having any relation on spring batch. Please advise are you using a custom writer and passing filepath from the bean or its a static variable in code.

Caused by: org.hibernate.DuplicateMappingException: Duplicate query mapping

This is a spring boot 2 application.
An entity having 2 named queries, which is throwing exception while starting the server like "Caused by: org.hibernate.DuplicateMappingException: Duplicate query mapping EstCredentials.findAppDepartment"
#Entity
#Table(name = EntityConstants.TABLE_EST_CREDENTIALS)
#NamedNativeQueries({
#NamedNativeQuery(name = "Credentials.findAppDepartment", query = "SELECT (deptmast.deptid) as deptId, deptname as deptName"
+ " FROM deptmast, doctdept" + " WHERE deptmast.deptid = doctdept.deptid ", resultSetMapping = "APP_DEPARTMENT"),
#NamedNativeQuery(name = "Credentials.findAppClinic", query = "SELECT A.DOCTDEPTID as doctdeptId, A.DOCTDEPTNAME as doctDeptName, "
+ " FROM DOCTDEPT A, DEPTMAST B"
+ " WHERE A.WORKING = 1", resultSetMapping = CommonConstants.APP_CLINIC_RESULT_MAP) })
#SqlResultSetMappings({
#SqlResultSetMapping(name = "APP_DEPARTMENT", classes = {
#ConstructorResult(targetClass = InstituteDepartmentDto.class, columns = {
#ColumnResult(name = "deptId", type = Long.class),
#ColumnResult(name = "deptName", type = String.class) }) }),
#SqlResultSetMapping(name = CommonConstants.APP_CLINIC_RESULT_MAP, classes = {
#ConstructorResult(targetClass = InstituteDoctorDepartmentDto.class, columns = {
#ColumnResult(name = "docDeptId", type = Long.class),
#ColumnResult(name = "doctDeptname", type = String.class) }) })
})
public class Credentials {
private Long estCode;
private String dbUserName;
private String dbPassword;
public Credentials() {
}
}
Let me know if need any other details.
Generally, it pays to assume that error messages are right.
In this case, you have a duplicate mapping for a query named: "EstCredentials.findAppDepartment". You defined this name in CommonConstants.APP_DEPARTMENT_RESULT_MAP and then use it twice, for two different mappings.

Cassandra select by timeuuid

Spring-boot-data-cassandra
CQL:
CREATE TABLE device_data (
device_id uuid,
time timeuuid,
unit text,
value double,
PRIMARY KEY (device_id, time)
)
Repository:
public interface DeviceDataRepository extends CassandraRepository<DeviceData> {
#Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, Date from);
}
Usage:
Calendar calendar = new GregorianCalendar(1990, 1, 1);
List<DeviceData> pump1Data = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(pumpid), calendar.getTime());
This gives me the following error:
Invalid INTEGER constant (633826800000) for "time" of type timeuuid; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Invalid INTEGER constant (633826800000) for "time" of type timeuuid
What am I doing wrong?
Fixed the issue:
#Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, UUID from);
DeviceData:
...
private UUID time;
...
Controller:
List<DeviceData> pumpData = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(id), calendar.getTime());

Query works fine in MySql but returns no records with JdbcTemplate

I have the following service method:
public Page<ProductSalesReportLineDto> getReport(
Unit unit, Organization customer, Organization supplier, Date startDate, Date endDate, Pageable pageable
){
List<ProductSalesReportLineDto> lines = new ArrayList<ProductSalesReportLineDto>();
String sql = "SELECT product.id, product.code as code, product.barcode as barcode, product_name.name__text AS name, " +
"SUM(order_line.quantity) as quantity, SUM(order_line.commissioned_price_price * order_line.quantity) as price " +
"FROM product LEFT JOIN order_line ON order_line.product_id = product.id " +
"JOIN `order` ON order_line.order_id = order.id " +
"JOIN product_name ON product_name.product_id = product.id " +
"WHERE product_name.name__locale = \"en-US\" " +
"AND (:customer is null OR :customer='' OR `order`.customer_id = :customer) " +
"AND (:supplier is null OR :supplier='' OR `order`.supplier_id = :supplier) " +
"AND (:startDate is null OR :startDate='' OR `order`.date >= :startDate) " +
"AND (:endDate is null OR :endDate='' OR `order`.date <= :endDate) " +
"AND (:unit is null OR :unit='' OR product.unit = :unit) " +
"GROUP BY product.id, product_name.name__text " +
"LIMIT :offset, :pageSize";
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("offset", pageable.getOffset());
parameters.put("pageSize", pageable.getPageSize());
parameters.put("customer", customer != null ? customer.id : null);
parameters.put("supplier", supplier != null ? supplier.id : null);
parameters.put("startDate", startDate);
parameters.put("endDate", endDate);
parameters.put("unit", unit);
List<Map<String, Object>> rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
for (Map<String, Object> row : rows) {
ProductSalesReportLineDto line = new ProductSalesReportLineDto();
line.productName = row.get("name") != null ? row.get("name").toString() : "";
line.productCode = row.get("code") != null ? row.get("code").toString() : "";
line.productBarcode = row.get("barcode") != null ? row.get("barcode").toString() : "";
line.quantity = row.get("quantity") != null ? Double.parseDouble(row.get("quantity").toString()) : 0;
line.price = row.get("price") != null ? Double.parseDouble(row.get("price").toString()) : 0;
lines.add(line);
}
Page<ProductSalesReportLineDto> page = new PageImpl<ProductSalesReportLineDto>(lines);
return page;
}
The parameters come from a #RestController method:
public #ResponseBody
ResponseEntity<?> get(
#RequestParam(value = "unit", required = false) Unit unit,
#RequestParam(value = "customer", required = false) Organization customer,
#RequestParam(value = "supplier", required = false) Organization supplier,
#DateTimeFormat(pattern = "yyyyy-MM-dd") #RequestParam(value = "startDate", required = false) Date startDate,
#DateTimeFormat(pattern = "yyyyy-MM-dd") #RequestParam(value = "endDate", required = false) Date endDate,
Pageable pageable
)
And Unit is an enum type field on Product:
#Enumerated(EnumType.STRING)
public Unit unit;
public enum Unit {
ROLL("ROLL", "ROLL", AbstractUnit.ONE),
METRE("METRE", Units.METRE.getSymbol(), Units.METRE),
KILOGRAM("KILOGRAM", Units.KILOGRAM.getSymbol(), Units.KILOGRAM),
PIECE("PIECE", "PIECE", AbstractUnit.ONE),
SAMPLE("SAMPLE", "SAMPLE", AbstractUnit.ONE);
I cannot retrieve products by unit using this query. With MySql the query works fine and it returns records. For example:
SELECT product.id, product.code as code, product.barcode as barcode, product_name.name__text AS name, SUM(order_line.quantity) as quantity, SUM(order_line.commissioned_price_price) as price FROM product LEFT JOIN order_line ON order_line.product_id = product.id JOIN `order` ON order_line.order_id = `order`.id JOIN product_name ON product_name.product_id = product.id WHERE product_name.name__locale = "en-US" AND (null is null OR null='' OR `order`.customer_id = null) AND (null is null OR null='' OR `order`.supplier_id = null) AND (null is null OR null='' OR `order`.date >= null) AND (null is null OR null='' OR `order`.date <= null) AND ("ROLL" is null OR "ROLL"='' OR product.unit = "ROLL") GROUP BY product.id, product_name.name__text
This query returns one row. When I run the same query via the rest interface and NamedParameterJdbcTemplate it returns no records. Can anybody tell what I am missing?
Following code also returns one row:
String sql2 = "SELECT * FROM product WHERE product.unit = :unit";
Map<String, Object> parameters2 = new HashMap<String, Object>();
parameters2.put("unit", "ROLL");
List<Map<String, Object>> rows2 = namedParameterJdbcTemplate.queryForList(sql2, parameters2);

Getting Randomly Error:Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists:

In my program code and entity are working fine, but randomly at any point of time this error comes.
If i restart the server's it starts working but after some days again same issue is coming.
Below are the log scripts of the error:
com.pb.gpp.backoffice.job.Exception.GPPBackOfficeException: Error occured during select operation in following method and tablegetFileTypeDetail, transactionfiletype and transactionfiledetail
at com.pb.gcs.backoffice.transaction.controller.DaoImpl.getFileTypeDetail(DaoImpl.java:74)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy178.getFileTypeDetail(Unknown Source)
at com.pb.gcs.backoffice.transaction.filecreate.writer.TransactionFileWriter.getCompletePath(TransactionFileWriter.java:178)
at com.pb.gcs.backoffice.transaction.filecreate.writer.TransactionFileWriter.initializeItemWriter(TransactionFileWriter.java:163)
at com.pb.gcs.backoffice.transaction.filecreate.writer.TransactionFileWriter.beforeStep(TransactionFileWriter.java:61)
... 16 more
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.pb.gcs.backoffice.transaction.model.configuration.TransactionfiledetailEntity#311]
at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:244)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1098)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1025)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:671)
at org.hibernate.type.EntityType.resolve(EntityType.java:489)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:667)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:349)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:190)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2926)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1673)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1605)
at org.hibernate.loader.Loader.getRow(Loader.java:1505)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:713)
at org.hibernate.loader.Loader.processResultSet(Loader.java:943)
at org.hibernate.loader.Loader.doQuery(Loader.java:911)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
public FileTypeDetail getFileTypeDetail(String partnerId, String carrier) throws GPPBackOfficeException {
try {
Session session = configurationSessionFactory.getCurrentSession();
session.clear();
String query = " Select tft.*, tfd.*" +
"from transactionfiletype tft " +
"join transactionfiledetail tfd " +
"on tft.filetype=tfd.filetype " +
"where tfd.activeflag=1 and tfd.filetype ='transactionfile' and tfd.partnerid =:partnerId and tfd.carrier =:carrier";
Query queryFileTypeMapping = session.createSQLQuery(query)
.addEntity("transactionfiletype", TransactionfiletypeEntity.class)
.addEntity("transactionfiledetail", TransactionfiledetailEntity.class);
queryFileTypeMapping.setParameter("partnerId", partnerId);
queryFileTypeMapping.setParameter("carrier", carrier);
List<Object[]> resultList = queryFileTypeMapping.list();
session.flush();
List<FileTypeDetail> fileTypeDetailList = new ArrayList<FileTypeDetail>();
FileTypeDetail fileTypeDetail;
for (Object[] fileDetail : resultList) {
fileTypeDetail = new FileTypeDetail();
fileTypeDetail.setTransactionfiletypeEntity((TransactionfiletypeEntity) fileDetail[0]);
fileTypeDetail.setTransactionfiledetailEntity((TransactionfiledetailEntity) fileDetail[1]);
fileTypeDetailList.add(fileTypeDetail);
}
return fileTypeDetailList.get(0);
} catch (Exception ex) {
GPPBackOfficeException gppBackOfficeException = new GPPBackOfficeException(Constants.SYSTEM_PREFIX, Constants.ERROR_CODE_0019, helper.getExceptionInfo(Constants.SYSTEM_PREFIX, Constants.ERROR_CODE_0019).getErrorclientmessage()
+ "getFileTypeDetail, transactionfiletype and transactionfiledetail", ex);
throw gppBackOfficeException;
}
}

Resources