Just want to call Stored procedure of SQL server from java using Hibernate as ORM.
The stored Procedure has so many result set which I am keeping it in Java as DTO's and each one as list in one DTO to send as JSON payload for Front-end integration.
But I am getting exception saying"org.hibernate.MappingException: Unknown entity: com.test.plans.dto.TemplatesDTO"
public ItemDetailsDTO getItemDetails(int no) {
Session session = getSession();
Connection connection = null;
List<ItemDetailsDTO> resultList = new ArrayList<>();
try {
ResultSet rs = null;
SessionImpl sessionImpl = (SessionImpl) session;
connection = sessionImpl.connection();
Query query = session.createSQLQuery("exec usp_GetItemDetails :no")
.addEntity(TemplatesDTO.class)
.setParameter("no", no);
resultList = query.list();
} catch (Exception e) {
System.out.println("error");
e.printStackTrace();
}
return resultList.get(0);
}
DTO :
import java.util.List;
public class ItemDetailsDTO {
private List<TemplatesDTO> templates;
public List<TemplatesDTO> gettemplates() {
return templates;
}
public void settemplates(List<TemplatesDTO> templates) {
this.templates = templates;
}
}
Please find below complete trace of exception
org.hibernate.MappingException: Unknown entity: com.test.plans.dto.TemplatesDTO
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:783)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:358)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:411)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:378)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:180)
at org.hibernate.loader.custom.sql.SQLCustomQuery.(SQLCustomQuery.java:71)
at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:70)
at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:210)
at org.hibernate.internal.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:306)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
at nbcu.compass.contingencyplans.dao.impl.ContDAOImpl.getItemDetails(ContingencyDAOImpl.java:503)
at nbcu.compass.contingencyplans.dao.impl.ContDAOImpl$$FastClassBySpringCGLIB$$c2b97106.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.test.plans.dao.impl.ContDAOImpl$$EnhancerBySpringCGLIB$$a1741e1f.getItemDetails()
at com.test.plans.service.impl.ContPlanServiceImpl.getConditionScheduleItemDetails(ContingencyPlanServiceImpl.java:316)
at test.plans.plans.rest.impl.PlanResourceImpl.getItemDetails(PlanResourceImpl.java:87)
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
Related
Got a huge problem with quartz Job in Confluence, regarding the page creation.
QUARTZ Job class:
#ComponentImport
private final SpaceManager spaceManager;
#Autowired
private final GeneralConfig config;
#Autowired
private final PageCreator pageCreator;
#ComponentImport
private final PageManager pageManager;
#Autowired
public ReportingPluginJob(GeneralConfig config, SpaceManager spaceManager, PageCreator pageCreator,
PageManager pageManager) {
this.config = config;
this.spaceManager = spaceManager;
this.pageCreator = pageCreator;
this.pageManager = pageManager;
}
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ReportingPluginJob.class);
#Override
public void execute(JobExecutionContext jec) throws JobExecutionException {
Collection<String> keys = spaceManager.getAllSpaceKeys(SpaceStatus.CURRENT);
String parentPageName = config.getSchedulerWeeklyParentPageName();
for (String key : keys) {
Page parentPage
= pageManager.getPage(key, parentPageName);
if (parentPage != null) {
LOG.debug("Creating weekly report for space " + key);
long pageId = parentPage.getId();
try {
pageCreator.createEazyBiReport(key, pageId);
} catch (ApplicationException e) {
LOG.error("FAILED TO CREATE A REPORT FOR SPACE " + key + " with error: " + System.lineSeparator()
+ e.getMessage());
}
}
}
}
PAGE CREATION class:
Space space = spaceManager.getSpace(spaceKey);
if (page != null) {
page.setTitle(pageTitle);
page.setSpace(space);
page.setVersion(1);
page.addLabelling(new Labelling(label, page.getEntity(), AuthenticatedUserThreadLocal.get()));
page.setCreator(AuthenticatedUserThreadLocal.get());
page.setCreationDate(new Date());
Page parent = pageManager.getPage(parentId);
if (parent != null) {
parent.addChild(page);
}
}
pageManager.saveContentEntity(page, DefaultSaveContext.builder().suppressNotifications(true).build());
attachmentProvider.attachExcelFileToPage(page);
AND Finally the exception which is driving me mad:
org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#31653891]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#31653891]
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:259)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:362)
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:326)
at org.springframework.orm.hibernate5.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:704)
at com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao.saveRaw(HibernateObjectDao.java:207)
at com.atlassian.confluence.pages.persistence.dao.hibernate.CachingPageDao.saveRaw(CachingPageDao.java:157)
at com.atlassian.confluence.core.DefaultContentEntityManager.saveContentEntity(DefaultContentEntityManager.java:150)
at com.atlassian.confluence.pages.DefaultPageManager.saveContentEntity(DefaultPageManager.java:1388)
at sun.reflect.GeneratedMethodAccessor2132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at com.atlassian.confluence.util.profiling.ConfluenceMonitoringMethodInterceptor.invoke(ConfluenceMonitoringMethodInterceptor.java:34)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy105.saveContentEntity(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2132.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
at com.sun.proxy.$Proxy253.saveContentEntity(Unknown Source)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy2863.saveContentEntity(Unknown Source)
at com.censored.atlassian.plugins.service.PageCreator.createEazyBiReport(PageCreator.java:128)
at com.censored.atlassian.plugins.service.ReportingPluginJob.execute(ReportingPluginJob.java:64)
at com.atlassian.confluence.plugin.descriptor.JobModuleDescriptor$DelegatingPluginJob.lambda$execute$0(JobModuleDescriptor.java:113)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:87)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:71)
at com.atlassian.confluence.plugin.descriptor.JobModuleDescriptor$DelegatingPluginJob.execute(JobModuleDescriptor.java:112)
at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
at com.atlassian.confluence.schedule.quartz.ConfluenceQuartzThreadPool.lambda$runInThread$0(ConfluenceQuartzThreadPool.java:16)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
According the stack trace, I've got a problem during the page save (saveContentEntity). It seems, the page save needs to update a space associated with the page too.
And here comes the problem. According to the stack trace, this space exists in the Hibernate session already. evict and clear of the actual session does not work.
Any suggestions, how can I handle this exception, or how can I actually remove the space from Hibernate session?
Apparently, this is what's happening in your code:
Within your SpaceManager, your session finds a Session object with ID 1 (assume that) and returns it.
Your method uses this reference to associate with another object, a Page one.
And finally, your PageManager persist this data in the database.
Probably, your problem is problem that:
From step 1 to 2, when the SpaceManager returns the data, your transaction is ended and your returned object becomes detached.
After that, when you call save, you are trying to persist a detached Session, but it already exists in the database. Then you get an exception.
You could try to use the merge method or remove the cascade from this reference in your entity.
(Please provide your entity code so I can improve my answer if there's anything wrong or which don't work for you.)
We ran into the same problem and what solved it for us was to put the code that creates the page (and loads other objects, like the space or the parent page) all into a transaction:
private void createNewPage(String title, String pageInput, Long parentPageId, String spaceKey) {
transactionTemplate.execute(() -> {
Page page = new Page();
page.setTitle(title);
page.setBodyAsString(pageInput);
Space space = spaceManager.getSpace(spaceKey);
page.setSpace(space);
Page parentPage = pageManager.getPage(parentPageId);
if (parentPage != null) {
page.setParentPage(parentPage);
parentPage.addChild(page);
}
pageManager.saveContentEntity(page, DefaultSaveContext.DEFAULT);
return null;
});
}
com.atlassian.sal.api.transaction.TransactionTemplate can be injected with #ComponentImport
I am unable to query a GeoSpatial Query of within in spring data mongodb, whether I write a custom query or spring data interface query I am getting this error and the same query is working fine from mongodb client(robomongo):
Following is the Query:
distanceRepository.findDistanceBySrcWithin(srcCircle);
Below is the mongo configurations:
#Override
public MongoClient mongo() throws Exception {
List<MongoCredential> mongoCredentials = new ArrayList<>();
mongoCredentials.add(MongoCredential.createCredential(userName, "admin", password.toCharArray()));
return new MongoClient(new ServerAddress(host, port), mongoCredentials);
}
#Override
#Bean
public MongoTemplate mongoTemplate() throws Exception {
MultiTenantMongoDbFactory mongoDbFactory = (MultiTenantMongoDbFactory) mongoDbFactory();
MongoTypeMapper typeMapper = new DefaultMongoTypeMapper(null);
MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), new MongoMappingContext());
converter.setTypeMapper(typeMapper);
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, converter);
mongoDbFactory.setMongoTemplate(mongoTemplate);
return mongoTemplate;
}
#Override
#Bean
public MongoDbFactory mongoDbFactory() throws Exception {
return new MultiTenantMongoDbFactory(mongo(), dbName);
}
Following is the stack trace:
2017-09-12 15:51:00 ERROR [JobDurationServiceImpl]:250 - Error in method getDistance Reason: No converter found capable of converting from type [org.springframework.data.mongodb.core.query.GeoCommand] to type [com.mongodb.DBObject]
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.mongodb.core.query.GeoCommand] to type [com.mongodb.DBObject]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:313)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:176)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.convertToMongoType(MappingMongoConverter.java:979)
at org.springframework.data.mongodb.core.convert.QueryMapper.delegateConvertToMongoType(QueryMapper.java:393)
at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:381)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:327)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:277)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:215)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:130)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1760)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1750)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:624)
at org.springframework.data.mongodb.repository.query.MongoQueryExecution$CollectionExecution.execute(MongoQueryExecution.java:70)
at org.springframework.data.mongodb.repository.query.MongoQueryExecution$ResultProcessingExecution.execute(MongoQueryExecution.java:345)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:91)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy76.findDistanceBySrcWithin(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
The key is to add the below line:
converter.afterPropertiesSet();
after
MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(),
new MongoMappingContext());
converter.setTypeMapper(typeMapper);
while creating MongoTemplate
While using SpringBoot with MSSQL server stored proc, when the value is null, Stored proc fails to execute. the value have default as null while calling.
If the parameters are excluded, the proc works. But as these are optional parameters, what are my options to call the stored proc?
When i try to pass null while calling the stored procedure, it is failing with this error.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error calling CallableStatement.getMoreResults; SQL [saveInfo]; nested exception is org.hibernate.exception.SQLGrammarException: Error calling CallableStatement.getMoreResults] with root cause
java.sql.SQLException: Parameter #1 has not been set.
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1049)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:563)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:787)
at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:52)
at org.hibernate.procedure.internal.ProcedureOutputsImpl.<init>(ProcedureOutputsImpl.java:32)
at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:411)
at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:363)
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:234)
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:217)
at com.tda.etfmc.service.repository.ETFMgmtRepository.saveCommissionFreeETF(ETFMgmtRepository.java:87)
at com.tda.etfmc.service.repository.ETFMgmtRepository$$FastClassBySpringCGLIB$$d1d68142.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
StoredProc:
CREATE PROCEDURE [dbo].[saveInfo]
#input1 varchar(16) = NULL,
#input2 varchar(16) = NULL
AS
BEGIN
//do save here
END
GO
#Repository
public class MyRepository {
private EntityManager entityManager;
public MyRepository(EntityManager entityManager) {
this.entityManager = entityManager;
}
#Procedure(name = "saveInfo")
#Transactional
public void saveInfo(List<Input> inputList) throws SQLException {
StoredProcedureQuery saveInfo;
for (Input input : inputList) {
saveInfo = entityManager.createNamedStoredProcedureQuery("saveInfo");
saveInfo.setParameter("input1", input.getInput1());// pass null here
saveInfo.setParameter("input2", input.getInput2());
saveInfo.execute();
}
}
}
#Data
#NamedStoredProcedureQuery(name = "saveInfo", procedureName = "saveInfo", parameters = {
#StoredProcedureParameter(name = "input1", type = String.class, mode = ParameterMode.IN),
#StoredProcedureParameter(name = "input2", type = String.class, mode = ParameterMode.IN) })
class Input implements Serializable {
private static final long serialVersionUID = 1L;
#Column(name = "#input1")
private String input1;
#Column(name = "#input2")
private String input2;
}
Please help in multithreaded scenario rarely I get NullPointerException in below code
public class CassPerfInterceptor {
private static final Logger log = LoggerFactory
.getLogger(CassPerfInterceptor.class);
private Performance performance;
#Autowired
private QueueServerMbean queueServerMbean;
#Around("target(org.springframework.data.repository.CrudRepository) || execution(public * com.owmessaging.*.dao.*.*Dao.*(..))")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
try {
Object obj = joinPoint.proceed();
performance = StatsProvider.getCassandraStats(joinPoint.getSignature().getName());
if(performance != null){
// Here I am getting NPE line number 30
performance.add(System.currentTimeMillis()-start, false);
}
return obj;
}catch(DriverException de){
queueServerMbean.sendNotification("CRITICAL", "DB Connectivity Error: "+de.getMessage());
throw de;
}
catch(Exception e){
log.error("Error: ",e);
performance = StatsProvider.getCassandraStats(joinPoint.getSignature().getName());
if(performance != null){
performance.add(System.currentTimeMillis()-start, true);
}
throw e;
}
}
}
Below is the stack trace:
11126 2016-07-04 17:16:58,448[http-nio-8014-exec-16]ERROR CassPerfInterceptor -Error:
11127
java.lang.NullPointerException
11128 at com.owmessaging.qserv.stats.CassPerfInterceptor.invoke(CassPerfInterceptor.java:31)
11129 at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
11130 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11131 at java.lang.reflect.Method.invoke(Method.java:497)
11132 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
11133 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
11134 at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
11135 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
11136 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
11137 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
11138 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
11139 at com.sun.proxy.$Proxy79.insertMsgInfo(Unknown Source)
11140 at com.owmessaging.qserv.service.impl.QueueServiceImpl.enqueue(QueueServiceImpl.java:151)
Even if I applied preventive check if (performance != null) still I am getting NPE. Is the above check no thread safe. (But note that this is very rare case I got I NPE out of 7000 request.)
I'm trying to connect to a mainframe via java using iway telnet, this is the connection code:
public static Session conexion(String nodo,int port) throws TnDriverException {
TnDriver driver = new TnDriver();
driver.setHost(nodo);
driver.setPort(port);
driver.setEmulation(Terminal.TN_3270);
driver.setTraceOn(false);
driver.setExtendedAttributes(true);
driver.setLanguage("Cp037");
driver.setTimerTimeout(25);
driver.setTimerOn(true);
session = driver.getSession();
logger.info("CONNECTED TO MAINFRAME.");
return session;
}
During the process of connecting to the mainframe I'm getting the next exception in the first screen:
ibi.telnet.api.TnDriverException: Connection is closed...
at ibi.telnet.api.Session.waitFor(Session.java:453)
at ibi.telnet.api.Session.waitFor(Session.java:393)
at ibi.telnet.api.Session.waitFor(Session.java:312)
at
tn3270.GestionPantallas.identificaPantalla(GestionPantallas.java:73)
at
tn3270.CertificacionSindo.getTransaccion(CertificacionSindo.java:67)
at
ws.Pensiones.obtenerCertificacion(Pensiones.java:41)
at sun.reflect.GeneratedMethodAccessor486.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at weblogic.wsee.component.pojo.JavaClassComponent.invoke(JavaClassComponent.java:99)
at weblogic.wsee.ws.dispatch.server.ComponentHandler.handleRequest(ComponentHandler.java:64)
at weblogic.wsee.handler.HandlerIterator.handleRequest(HandlerIterator.java:137)
at weblogic.wsee.ws.dispatch.server.ServerDispatcher.dispatch(ServerDispatcher.java:109)
at weblogic.wsee.ws.WsSkel.invoke(WsSkel.java:80)
at weblogic.wsee.server.servlet.SoapProcessor.handlePost(SoapProcessor.java:66)
at weblogic.wsee.server.servlet.SoapProcessor.process(SoapProcessor.java:44)
at weblogic.wsee.server.servlet.BaseWSServlet$AuthorizedInvoke.run(BaseWSServlet.java:257)
at weblogic.wsee.server.servlet.BaseWSServlet.service(BaseWSServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3395)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2140)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2046)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
And this is the method identificaPantalla in the class GestionPantallas, where the conexion method is.
public static int identificaPantalla(ScreenDesc[] pantallas) throws TnDriverException {
int result = -1;
try {
result = session.waitFor(pantallas);
}
catch(TnDriverException e) {
throw e;
}
return result;
}
Any idea about this issue?