The Org. hibernate. lazyinitializationexception: failed to lazily initialize a collection of Role: Org. jbpm. PVM. internal. model. executionimpl. variables, no session or session was closed
CodeAs follows:
Executionservice = processengine. getexecutionservice ();
Processinstance executionservice. createprocessinstancequery (). processdefinitionid (processinstanceid). List ();
(Executionimpl) processinstance2). removevariable ("AA"); // an error is returned when the variable AA is deleted. Because the variable setting is a solution to delayed loading: If BS development mode is used, you can configure opensessioninviewfilter in Web. XML (Note: It must be written under struts configuration) <filter>
<Filter-Name> opensessioninviewfilter </filter-Name>
<Filter-class>
Org. springframework. Orm. hibernate3.support. opensessioninviewfilter
</Filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> opensessioninviewfilter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping> Add in application. xml
<! -- @ Transactional flag is supported -->
<TX: annotation-driven transaction-Manager = "transactionmanager"/>
<! -- @ Aspectj flag is supported -->
<AOP: aspectj-autoproxy/>
<AOP: config proxy-target-class = "true">
<AOP: Advisor pointcut = "execution (* org. jbpm ..*.*(..))"
Advice-ref = "txadvice"/>
<AOP: Advisor pointcut = "execution (* COM. Jihong. jbpm. API. jbpmtemplate .*(..))"
Advice-ref = "txadvice"/>
</AOP: config>
Solution 2: Execute the processengine method to put a piece of code into a hibernate transaction and execute it to avoid delayed loading.
Public class removevarcommand implements command <void> {
Private string processinstanceid;
Private string varkey;
Public removevarcommand (string processinstanceid, string varkey ){
This. processinstanceid = processinstanceid;
This. varkey = varkey;
}
@ Override
Public void execute (environment) throws exception {
Executionservice = environment. Get (executionservice. Class );
Processinstance = executionservice. findprocessinstancebyid (processinstanceid );
(Executionimpl) processinstance). removevariable (varkey );
Return NULL;
}
}
Processengine.exe cute (New removevarcommand (processinstance. GETID (), "AA "));
Each Command is an independent transaction operation, and each excuete method is included by a hibernate firm. jbpm recommends using this method to expand related functions.