nested exception is org.hibernate.exception.SQLGrammarException: could not execute query - java

This is the error I am getting. I have been stuck for 2 hours but could not resolve it.My code for hibernate is as follows:-
Session session1=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
org.hibernate.cfg.Configuration cfg=new org.hibernate.cfg.Configuration();
cfg.configure("hibernate.cfg.xml");
//creating seession factory object
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
String hql = "SELECT E.id FROM User E where firstName=:name";
SQLQuery query = session1.createSQLQuery(hql);
query.setParameter("name", name);
List results = query.list();
Iterator itr=results.iterator();
String id="";
while(itr.hasNext()){ id=String.valueOf(itr.next());}
//creating transaction object
Transaction t=session.beginTransaction();
User employee =
(User)session.get(User.class, 2);
employee.setMessage(chat);
session.update(employee);
//template.save(e1);
//session.persist(user);//persisting the object
t.commit();//transaction is committed
session.close();
return "hello";
Any help would be appreciated..thanx in advance.
My full stack trace is as follows:-
Stack Trace
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:74
5)

Try this
String hql = "SELECT u.id FROM User u where u.firstName = :name";
Query query = session1.createQuery(hql);
query.setParameter("name", name);
List results = query.getResultList();
Iterator itr=results.iterator();
String id="";
while(itr.hasNext()){ id=String.valueOf(itr.next());}

Related

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

I have a problem when using 'fetch' in a consultation, which is responsible for redeeming a PPA and, from it, its programs, which in turn, redeem shares, and for this reason fetch is used. When fetch is not used, the query works normally, but, due to the above needs, it is necessary.
Method with a query:
public PPA localizarPPACompleta(Long idPpa) {
String sql = "SELECT a FROM br.gov.ac.tce.icuria.modelo.entidades.planejamento.PPA a LEFT JOIN FETCH a.programas AS p LEFT JOIN FETCH p.acoes WHERE a.id = :idPpa";
TypedQuery<PPA> query = entityManager.createQuery(sql, PPA.class);
query.setParameter("idPpa", idPpa);
try {
return query.getSingleResult();
} catch (NoResultException ne) {
return null;
}
}
PPA class mapping:
#EntidadeDoPlanejamento
#XmlRootElement
#XmlType(propOrder = {})
#XmlAccessorType(XmlAccessType.FIELD)
#Entity(name = "br.gov.ac.tce.icuria.modelo.entidades.planejamento.PPA")
#AttributeOverride(name = "id", column = #Column(name = "ID_PPA"))
#Table(name = "PPA", schema = "planejamento", uniqueConstraints = {
#UniqueConstraint(name = "UQ__PPA_1", columnNames = { "ID_ENTIDADE",
"ANO_INICIAL_VIGENCIA", "ANO_FINAL_VIGENCIA" }),
#UniqueConstraint(name = "UQ__PPA_2", columnNames = { "NUMERO_LEI",
"ID_ENTIDADE" }) })
#NamedQuery(name = "PPA.porChaveLogica", query = "select p from br.gov.ac.tce.icuria.modelo.entidades.planejamento.PPA p where p.ano = :ano and p.entidade = :entidade")
#Audited(auditParents = Cadastravel.class)
public class PPA extends Cadastravel implements IFDadosElegis {
private static final long serialVersionUID = -3581419763803965106L;
#NotNull
#Column(name = "NUMERO_LEI", nullable = false)
private Integer numero;
#CampoValidacao
#CampoChave
#NotNull
#Column(name = "ANO_LEI", nullable = false)
private Integer ano;
#CampoValidacao
#NotNull
#Column(name = "ANO_INICIAL_VIGENCIA", nullable = false)
private Integer anoInicialDeVigencia;
#CampoValidacao
#NotNull
#Column(name = "ANO_FINAL_VIGENCIA", nullable = false)
private Integer anoFinalDeVigencia;
#NotNull
#Column(name = "TIPO_LEI", nullable = false)
private TipoDaLei tipoDaLei;
#XmlTransient
#OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "ppa")
private Set<Programa> programas;
#XmlTransient
#OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "ppa")
private Set<LDO> ldos;
#XmlTransient
#Column(name = "CAMINHO_DOCUMENTO_ELEGIS", nullable = true)
private String caminhoDocumentoNoElegis;
#XmlTransient
#OneToMany(mappedBy = "ppa")
private Set<Orgao> orgaos;
Console error:
17:04:10,249 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-10) SQL Error: 207, SQLState: S0001
17:04:10,249 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-10) Nome de coluna 'br' inválido.
17:04:10,249 INFO [org.hibernate.event.internal.DefaultLoadEventListener] (default task-10) HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
17:04:10,249 INFO [javax.enterprise.resource.webcontainer.jsf.context] (default task-10) javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1514)
at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1553)
at org.jboss.as.jpa.container.TypedQueryNonTxInvocationDetacher.getSingleResult(TypedQueryNonTxInvocationDetacher.java:69)
at br.gov.ac.tce.icuria.persistencia.dao.PpaDAO.localizarPPACompleta(PpaDAO.java:39)
at br.gov.icuria.service.PPAService.localizarPPACompleta(PPAService.java:53)
at br.gov.icuria.service.PPAService$Proxy$_$$_WeldSubclass.localizarPPACompleta(Unknown Source)
at br.gov.icuria.conversor.PpaConverter.getIdentificavel(PpaConverter.java:21)
at br.gov.icuria.conversor.PpaConverter.getIdentificavel(PpaConverter.java:10)
at br.gov.icuria.conversor.ConversorGenerico.getAsObject(ConversorGenerico.java:23)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:147)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:146)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:208)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.getConvertedValue(SelectOneMenuRenderer.java:80)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1105)
at javax.faces.component.UIInput.validate(UIInput.java:1006)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1317)
at javax.faces.component.UIInput.processValidators(UIInput.java:733)
at javax.faces.component.UISelectOne.processValidators(UISelectOne.java:183)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:313)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
at org.primefaces.component.fieldset.Fieldset.processValidators(Fieldset.java:225)
at javax.faces.component.UIForm.processValidators(UIForm.java:229)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:608)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
at javax.faces.component.UIForm.visitTree(UIForm.java:365)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1307)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:53)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:81)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at br.gov.icuria.filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:46)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at br.gov.icuria.filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:46)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:55)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:419)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:191)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:121)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:188)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4273)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:511)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:481)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:222)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:281)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:124)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:92)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1257)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1140)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:682)
at org.hibernate.type.EntityType.resolve(EntityType.java:464)
at org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:239)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:172)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1151)
at org.hibernate.loader.Loader.processResultSet(Loader.java:1010)
at org.hibernate.loader.Loader.doQuery(Loader.java:948)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
at org.hibernate.loader.Loader.doList(Loader.java:2689)
at org.hibernate.loader.Loader.doList(Loader.java:2672)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
at org.hibernate.loader.Loader.list(Loader.java:2501)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
... 99 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Nome de coluna 'br' inválido.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1632)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:602)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:524)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7375)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3206)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:247)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:222)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:446)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
... 132 more
I am using the hibernate version 5.0.0.Final
Entity should be specified without package
String sql = "SELECT a FROM PPA a ...

Java transactions don't work when multiple entity managers are used

I have been working a couple of weeks on a requirement that requires modifing some methods that are using transactions, the code between the transaccion can read/update/delete/etc elements in the database(PostgreSQL) through the application. At this moment, the application is using a peristence unit (pointing to a wildfly datasource) and an entity manager to access the database:
For example:
#PersistenceContext( unitName="name", type = PersistenceContextType.TRANSACTION )
protected EntityManager em;
public String updateReadRead()
{
try
{
TransactionUtil.begin( this.utx );
Query nativeQuery = this.em.createNativeQuery("update schema.company_info set service_manager_phone_ext = '1004';");
int i = nativeQuery.executeUpdate();
this.searchCriteriaApplication.trimVo();
this.searchCriteriaCustomer.trimVo();
this.searchResults = this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.em, false, true );
this.showAccountsForCustomer = false;
this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.em, false, true );
TransactionUtil.commit(this.utx);
}
catch ( Exception e )
{
}
return null;
}
But now, we want to use two entity managers,one in charge of the write operations (pointing to a transaccional Data Base) and the other one for read operations (pointing to a replica Data Base (ReadOnly DataBase)), for example:
#PersistenceContext( unitName="readonly", type = PersistenceContextType.TRANSACTION )
protected EntityManager readOnlyEM;
#PersistenceContext( unitName="readwrite", type = PersistenceContextType.TRANSACTION )
protected EntityManager readWriteEM;
public String updateReadRead()
{
try
{
TransactionUtil.begin( this.utx );
Query nativeQuery = this.readWriteEM.createNativeQuery("update schema.company_info set service_manager_phone_ext = '1004';");
int i = nativeQuery.executeUpdate();
this.searchCriteriaApplication.trimVo();
this.searchCriteriaCustomer.trimVo();
this.searchResults = this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.readOnlyEM, false, true );
this.showAccountsForCustomer = false;
this.applicationSearchService.searchApplications( this.searchCriteriaApplication, this.searchCriteriaCustomer, this.readOnlyEM, false, true );
TransactionUtil.commit(this.utx);
}
catch ( Exception e )
{
}
return null;
}
I have tried two approaches:
Create a new entityManager pointing to the readonly database. It fails when we use the readonly entityManager and then, change to the write entityManager or vice versa (All ot this in the same transaction).
If we use two transactions, one for read operatios and the other one for write operations, it works.
(Please check error stacktrace below):
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:995)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:920)
at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:3341)
at org.jboss.as.jpa.container.AbstractEntityManager.remove(AbstractEntityManager.java:655)
at com.snap.web.bean.SmartEntityManager.remove(SmartEntityManager.java:68)
at com.snap.event.EventService.delete(EventService.java:221)
at com.snap.accountmanager.AccountManagerService.deletePriorityNote(AccountManagerService.java:3877)
at com.snap.api.AccountManagementResource.deletePriorityNote_aroundBody38(AccountManagementResource.java:1878)
at com.snap.api.AccountManagementResource$AjcClosure39.run(AccountManagementResource.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
at com.snap.common.log.MethodLogger.around(MethodLogger.java:62)
at com.snap.api.AccountManagementResource.deletePriorityNote(AccountManagementResource.java:1863)
at com.snap.api.AccountManagementResource$Proxy$_$$_WeldClientProxy.deletePriorityNote(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.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:130)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:162)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at
Use distributed transactions. I configured two new XA Data Sources and two new pesistence units associated to those datasources. I changed the entityManagers to point those new persistence units but the transaction fails when it tries to commit. I already set the max_prepared_transactions with the same value as maxSession property in both databases as the documentation suggests.
See stacktrace below:
javax.transaction.HeuristicMixedException
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1208)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:178)
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.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:433)
at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:42)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
at org.jboss.weldx.transaction.UserTransaction$112420245$Proxy$_$$_Weld$Proxy$.commit(Unknown Source)
at com.snap.common.utils.TransactionUtil.commit(TransactionUtil.java:71)
at com.snap.web.bean.application.SearchApplicationTransactionTests.smart_aroundBody4(SearchApplicationTransactionTests.java:339)
at com.snap.web.bean.application.SearchApplicationTransactionTests$AjcClosure5.run(SearchApplicationTransactionTests.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
at com.snap.common.log.MethodLogger.around(MethodLogger.java:62)
at com.snap.web.bean.application.SearchApplicationTransactionTests.smart(SearchApplicationTransactionTests.java:287)
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 com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:130)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:162)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Suppressed: org.postgresql.xa.PGXAException: Error preparing transaction
at org.postgresql.xa.PGXAConnection.prepare(PGXAConnection.java:323)
at org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.prepare(XAManagedConnection.java:330)
at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelPrepare(XAResourceRecord.java:218)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2662)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2612)
at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2155)
at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1501)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1200)
... 97 more
Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute PREPARE TRANSACTION during recovery
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244)
at org.postgresql.xa.PGXAConnection.prepare(PGXAConnection.java:315)
... 106 more
Suppressed: org.postgresql.xa.PGXAException: Error rolling back prepared transaction
at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:415)
at org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.rollback(XAManagedConnection.java:346)
at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelAbort(XAResourceRecord.java:369)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doAbort(BasicAction.java:3017)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doAbort(BasicAction.java:2996)
at com.arjuna.ats.arjuna.coordinator.BasicAction.phase2Abort(BasicAction.java:1979)
at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1517)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1200)
... 97 more
Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute ROLLBACK PREPARED during recovery
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244)
at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:405)
... 106 more
Is any of these approches correct? in order to continue testing or is there a better solution to achieve the requeriment?
I will appreciate any suggestion.
Thanks.

"could not reset reader" while saving BLOB

I was using Hibernate 3, now I'm migrating to Hibernate 5, and some problems occurred (of course).
I have several DAO objects that are stored via Hibernate, and some of them have parameter/field/column "modified" which is automatically updated to current time on each save/update in Hibernate.
This is simple DAO:
#Entity
#Table(name="attachments")
#SequenceGenerator(name="common_attachments_seq", sequenceName="common_attachments_seq", allocationSize=1)
public class AttachmentDAO implements Modifications {
private Long id;
private String name;
private Blob content;
private Date modified;
public AttachmentDAO() {}
#Id
#GeneratedValue(strategy=GenerationType.AUTO, generator="common_attachments_seq")
#Column(updatable = false, nullable = false)
public Long getId() {return this.id;}
public void setId(Long id) {this.id=id;}
#Column
public String getName() {return this.name;}
public void setName(String name) {this.name=name;}
#Column
public Blob getContent() {return this.content;}
public void setContent(Blob content) {this.content=content;}
#Column
public Date getModified() {return modified;}
public void setModified(Date date) {modified=date;}
}
This is integrator that sets modifications listener:
public class HibernateIntegrator implements Integrator {
#Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry eventListenerRegistry=serviceRegistry.getService(EventListenerRegistry.class);
ModificationsEventListener mod=new ModificationsEventListener();
eventListenerRegistry.appendListeners(EventType.UPDATE, mod);
eventListenerRegistry.appendListeners(EventType.SAVE, mod);
eventListenerRegistry.appendListeners(EventType.SAVE_UPDATE, mod);
}
#Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
}
This is ModificationsEventListener which actually updates "modified" parameter:
public class ModificationsEventListener extends DefaultSaveOrUpdateEventListener {
#Override
public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException {
Object o=event.getObject();
if (o instanceof Modifications) {
Date now=new Date();
Modifications doc=((Modifications)o);
doc.setModified(now);
}
super.onSaveOrUpdate(event);
}
}
This is the code that saves DAO:
// DiskFileItem currentFile = file uploaded to server - Apache's commons-fileupload-1.3.2.jar
Session hibSession=null;
Transaction tx=null;
try {
SessionFactory sf=AttachmentsSessionFactory.getSessionFactory();
hibSession=sf.openSession();
tx=hibSession.beginTransaction();
AttachmentDAO stub=new AttachmentDAO();
stub.setName(fileName);
long length=currentFile.getSize();
InputStream ins=currentFile.getInputStream(); // this is FileInputStream
LobCreator lobs=Hibernate.getLobCreator(hibSession);
Blob blob=lobs.createBlob(ins, length);
stub.setContent(blob);
hibSession.save(stub);
tx.commit();
ins.close();
currentFile.delete();
} catch (Exception ex) {
if (tx!=null) tx.rollback();
log.error("", ex);
} finally {
if (hibSession!=null&&hibSession.isOpen()) {
hibSession.close();
}
hibSession=null;
}
But this code throws error:
2017-05-12 11:20:38,253 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-127) could not reset reader
2017-05-12 11:20:38,254 ERROR [org.hibernate.internal.SessionImpl] (default task-127) HHH000346: Error during managed flush [could not update: [com.test.persistence.AttachmentDAO#38]]
2017-05-12 11:20:38,267 ERROR [com.gibon.qintegra.servlets.upload.AttachmentsUploadProgressListener] (default task-127) : org.hibernate.exception.GenericJDBCException: could not update: [com.gibon.qintegra.persistence.common.AttachmentDAO#38]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3111)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2961)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3341)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
at com.gibon.qintegra.servlets.upload.AttachmentsUploadProgressListener.currentFileFinished(AttachmentsUploadProgressListener.java:138)
at com.gibon.qintegra.data4ajax.AttachmentsServant.doServe(AttachmentsServant.java:255)
at com.gibon.qintegra.servlets.Data4Ajax.doProcess(Data4Ajax.java:74)
at com.gibon.qintegra.servlets.Data4Ajax.doPost(Data4Ajax.java:24)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at com.gibon.qintegra.filters.IECompatFilter.doFilter(IECompatFilter.java:44)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.gibon.qintegra.filters.SecurityFilter.doFilter(SecurityFilter.java:89)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: could not reset reader
at org.hibernate.engine.jdbc.BlobProxy.resetIfNeeded(BlobProxy.java:75)
at org.hibernate.engine.jdbc.BlobProxy.getUnderlyingStream(BlobProxy.java:64)
at org.hibernate.engine.jdbc.BlobProxy.getStream(BlobProxy.java:60)
at org.hibernate.engine.jdbc.BlobProxy.invoke(BlobProxy.java:101)
at com.sun.proxy.$Proxy118.getBinaryStream(Unknown Source)
at org.postgresql.jdbc.PgPreparedStatement.setBlob(PgPreparedStatement.java:1154)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.setBlob(WrappedPreparedStatement.java:1157)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$4$1.doBind(BlobTypeDescriptor.java:132)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:257)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:252)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:39)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2609)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3038)
... 67 more
sql that hibernate executes is this:
Hibernate:
select
nextval ('common_attachments_seq')
Hibernate:
insert
into
sys_attachments
(content, modified, name, id)
values
(?, ?, ?, ?)
Hibernate:
update
sys_attachments
set
content=?,
modified=?,
name=?,
where
id=?
Apparently problem is that Hibernate inserts record and right after that makes update. FileInputStream doesn't like it because it's closed right after insertion.
When I disable Integrator (updating "modified" field) then it works OK.
Is there any way how to make it work?
I have just seen this:
How to autogenerate created or modified timestamp field?
And it helped me to solve my problem. I had to use EventType.PRE_UPDATE and EventType.PRE_INSERT in Integrator, instead of EventType.SAVE_UPDATE, EventType.SAVE and EventType.UPDATE. And then update values in those listeners like this:
Modifications doc=((Modifications)entity);
doc.setModified(now);
setPropertyState(state, propertyNames, "modified", now);
Where property state setter is here:
private void setPropertyState(Object[] propertyStates, String[] propertyNames, String propertyName, Object propertyState) {
for(int i=0;i<propertyNames.length;i++) {
if (propertyName.equals(propertyNames[i])) {
propertyStates[i]=propertyState;
return;
}
}
}

How to get global variables from jbpm-process within WorkItem

I can successfully retrieve global variables (such as NodeInstance, ProcessInstance and so on) from within the process with help of Script-Task and kcontext-instance; But what if I need retrieve those global variables within WorkItem? I could of course put Script-Task before my WorkItem within Process and then assign a global variable to one of Variable Definitions, in order to use it within WorkItem with getParameter()-method;
But we do understand, that it is double made work, doesn't we?
So how could I get global variables within WorkItem without additional Script-Task? I thought firstly, that I could use the same name of the session within WorkItem, such we define by registering WorkItem in KieWorkBench, that's why I created a ProcessContext within my WI as follows:
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-process");
ProcessContext context = new ProcessContext(kSession);
Map<String, Object> params = new HashMap<>();
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("lane", context.getNodeInstance().getNode().getMetaData().get("Lane").toString());
manager.completeWorkItem(workItem.getId(), params);
}
With this code snippet within executeWorkItem(), but rather with kcontext in Script-Task I can retrieve successfuly the name of the Lane and assign it to variable, but when I execute the process with this WorkItem I get an Error - WorkItem -- null not by deploying, rather by starting the process; Of course I also registry the same ksession - name as within WorkItem (namely "ksession-process") in KieWorkBench, but apparently I cannot use the context this way, as I thought.
So I really appreciate your help! It doesn't really bother, but to make a code resp. BProcess a little bit concisely and without any redundant variables, it pays to ask.
jBPM 6.4, wildfly 8.2
UPDATE:
as user livthomas has suggested, instead of WorkItemHandler interface I've tried to extend my class to AbstractWorkiItemHandler as follows:
public class WI extends AbstractWorkItemHandler {
public WI(StatefulKnowledgeSession ksession) {
super(ksession);
}
KieSession kSession = getSession();
ProcessContext context = new ProcessContext(kSession);
Map<String, Object> params = new HashMap<>();
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
params.put("lane", context.getNodeInstance().getNode().getMetaData().get("Lane"));
manager.completeWorkItem(workItem.getId(), params);
}
...
And then register it in Project's descriptor.xml as new my_package.WI(ksession);
Unfortunately I get the RuntimeException: cannot instance WorkItem...
UPDATE2: STACK TRACE
2016-09-13 11:49:59,355 ERROR [org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl] (default task-24) Deployment of unit testing:testing-work-item-handler:1.0 failed: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI: org.jbpm.console.ng.bd.exception.DeploymentException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:203) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:158) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.process(DeploymentManagerEntryPointImpl.java:517) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl$Proxy$_$$_WeldClientProxy.process(Unknown Source) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl.doBuildAndDeploy(BuildServiceImpl.java:178) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl.buildAndDeploy(BuildServiceImpl.java:134) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at org.kie.workbench.common.services.backend.builder.BuildServiceImpl$Proxy$_$$_WeldClientProxy.buildAndDeploy(Unknown Source) [kie-wb-common-services-backend-6.4.0.Final.jar:6.4.0.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_72]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_72]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_72]
at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_72]
at org.jboss.errai.bus.server.io.AbstractRPCMethodCallback.invokeMethodFromMessage(AbstractRPCMethodCallback.java:48) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.io.ValueReplyRPCEndpointCallback.callback(ValueReplyRPCEndpointCallback.java:22) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.cdi.server.CDIExtensionPoints$2.callback(CDIExtensionPoints.java:410) [errai-weld-integration-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.DeliveryPlan.deliver(DeliveryPlan.java:47) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.ServerMessageBusImpl.sendGlobal(ServerMessageBusImpl.java:296) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.SimpleDispatcher.dispatchGlobal(SimpleDispatcher.java:46) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.service.ErraiServiceImpl.store(ErraiServiceImpl.java:97) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.service.ErraiServiceImpl.store(ErraiServiceImpl.java:114) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at org.jboss.errai.bus.server.servlet.DefaultBlockingServlet.doPost(DefaultBlockingServlet.java:142) [errai-bus-3.2.3.Final.jar:3.2.3.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.uberfire.ext.security.server.SecureHeadersFilter.doFilter(SecureHeadersFilter.java:69) [uberfire-servlet-security-0.8.0.Final.jar:0.8.0.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.uberfire.ext.security.server.SecurityIntegrationFilter.doFilter(SecurityIntegrationFilter.java:61) [uberfire-servlet-security-0.8.0.Final.jar:0.8.0.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_72]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_72]
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:201) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.services.cdi.impl.DeploymentServiceCDIImpl$Proxy$_$$_WeldClientProxy.deploy(Unknown Source) [jbpm-services-cdi-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.console.ng.bd.backend.server.DeploymentManagerEntryPointImpl.deploy(DeploymentManagerEntryPointImpl.java:194) [jbpm-console-ng-business-domain-backend-6.4.0.Final.jar:6.4.0.Final]
... 59 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
at org.jbpm.kie.services.impl.AbstractDeploymentService.commonDeploy(AbstractDeploymentService.java:161) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:196) [jbpm-kie-services-6.4.0.Final.jar:6.4.0.Final]
... 61 more
Caused by: java.lang.RuntimeException: Cannot instance WorkItemHandler bpmstest.test.WI
You need to either extend AbstractWorkItemHandler or implement your work item handler in a similar way. Then just pass ksession instance as a parameter of its constructor when you register it. Once you have a reference to KIE session, you can get global variables calling its getGlobals() method.

IllegalStateException in primefaces dropdown

I have a datatable which contains a dropdown, when I change the value in dropdown I am getting an exception saying IllegalStateException.
The datatable code is shared below.
<p:column width="180">
<f:facet name="header">
<h:outputText value="Data Type" />
</f:facet>
<p:selectOneMenu value="#{column.dataTypeConfigNameWithId}"
rendered="#{column.editHeaderDetails}"
valueChangeListener="#{returnHeaderBean.dataTypeChangeAction}"
style="width:280px">
<f:selectItems value="#{returnHeaderBean.dataTypes}"
var="dataType" itemLabel="#{dataTypestandardDataTypeDisplayName}"
itemDescription="#{dataType.dataTypeDescription}"
itemValue="#{dataType.standardDataTypeDisplayName}: #{dataType.id}" />
<p:ajax event="valueChange" process="cdHTable"
partialSubmit="true" update="#this" />
</p:selectOneMenu>
</p:column>
The Error which i am getting is
SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default
task-36) java.lang.IllegalStateException at
javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1052)
at
javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1054)
at javax.faces.component.UIInput.validate(UIInput.java:991) at
javax.faces.component.UIInput.executeValidate(UIInput.java:1248) at
javax.faces.component.UIInput.processValidators(UIInput.java:712) at
org.primefaces.component.api.UIData.process(UIData.java:339) at
org.primefaces.component.api.UIData.processChildren(UIData.java:323)
at org.primefaces.component.api.UIData.processPhase(UIData.java:285)
at
org.primefaces.component.api.UIData.processValidators(UIData.java:259)
at
org.primefaces.component.datatable.DataTable.processValidators(DataTable.java:622)
at
com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:575)
at
com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:692) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIForm.visitTree(UIForm.java:371) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at
com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at
com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
at
org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
at
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at
io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
at
io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
at
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
at
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
at
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
at
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
at
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
at
io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
at
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Bean Method called
public void dataTypeChangeAction(ValueChangeEvent vEvent) {
LOGGER.info("Inside dataTypeNameChange()");
try {
String typeNameWithId = (String) vEvent.getNewValue();
if (typeNameWithId != null) {
String[] dataTypeArray = typeNameWithId.split(":");
ReturnHeader column = (ReturnHeader) bindHdrElementsTable.getRowData();
column.getDataTypeConfig().setStandardDataTypeDisplayName(dataTypeArray[0]);
column.getDataTypeConfig().setId(Integer.parseInt(dataTypeArray[1]));
column.setDataTypeConfigId(Integer.parseInt(dataTypeArray[1]));
}
} catch (Exception e) {
LOGGER.error(e);
}
}

Categories

Resources