How to use JPA Workitem in Business Application project?

64 views
Skip to first unread message

Mohammed Abdulkareem

unread,
Oct 29, 2019, 6:18:24 AM10/29/19
to jBPM Setup
I am using currently the standard technique of jBPM Business Application as following:
- Business Application Kjar
- Business Application Model (I moved the models into Kjar application)
- Business Application Service

I tried to use JPA work item to do CRUD operations on Data Objects. it worked fine on Business-Central. but did not work on Business Application and got this errors:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is [Error: could not create constructor: null]
[Near : {... new org.jbpm.process.workitem.jpa. ....}]

and

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

My persistence.xml:

    <persistence-unit name="myPersistenceUnit" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
        <class>com.company.model.Person</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <property name="hibernate.max_fetch_depth" value="3"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.id.new_generator_mappings" value="false"/>
            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
        </properties>
    </persistence-unit>

and in my kie-deployment-descriptor.xml:

<work-item-handlers>
        <work-item-handler>
            <resolver>mvel</resolver>
            <identifier>new org.jbpm.process.workitem.jpa.JPAWorkItemHandler("myPersistenceUnit", classLoader)</identifier>
            <parameters/>
            <name>JPA</name>
        </work-item-handler>
    </work-item-handlers>

Maciej Swiderski

unread,
Oct 30, 2019, 2:27:55 PM10/30/19
to Mohammed Abdulkareem, jBPM Setup
In business app you don’t need to use deployment descriptor as it supports work item handlers as spring beans so just produce bean of the JpaWprkItemHandler where you can inject proper entity manager factory again as spring bean. 

Maciej

Wiadomość napisana przez Mohammed Abdulkareem <mohammed.a...@healthcubator.com> w dniu 29.10.2019, o godz. 11:18:


--
You received this message because you are subscribed to the Google Groups "jBPM Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-setup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-setup/15924d5a-fa67-4fa9-add9-fb0bab46adc4%40googlegroups.com.

Mohammed Abdulkareem

unread,
Oct 30, 2019, 7:24:32 PM10/30/19
to jBPM Setup
Thanks for you feedback!

My goal is creating and testing the business process on business-applcation-kjar project in Business Central, then pull it to business-applcation-kjar in business-applcation then start it in business-applcation-service using "processService.startProcess(deploymentId, processId, params); ... etc" in easiest way.

Do you mean, I have to create class like this https://github.com/kiegroup/jbpm-work-items/blob/master/jpa-workitem/src/main/java/org/jbpm/process/workitem/jpa/JPAWorkItemHandler.java ? or I have to do like this https://docs.jboss.org/jbpm/release/7.28.0.Final/jbpm-docs/html_single/#_register_work_item_handler_programmatically ?

Do you have a sample that make it more clearly to me? because I'm new with jBPM Technology.


Am Mittwoch, 30. Oktober 2019 19:27:55 UTC+1 schrieb Maciej Swiderski:
In business app you don’t need to use deployment descriptor as it supports work item handlers as spring beans so just produce bean of the JpaWprkItemHandler where you can inject proper entity manager factory again as spring bean. 

Maciej

Wiadomość napisana przez Mohammed Abdulkareem <mohammed....@healthcubator.com> w dniu 29.10.2019, o godz. 11:18:

To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-...@googlegroups.com.

Maciej Swiderski

unread,
Nov 3, 2019, 4:48:29 AM11/3/19
to Mohammed Abdulkareem, jBPM Setup


Wiadomość napisana przez Mohammed Abdulkareem <mohammed.a...@healthcubator.com> w dniu 31.10.2019, o godz. 00:24:


Thanks for you feedback!

My goal is creating and testing the business process on business-applcation-kjar project in Business Central, then pull it to business-applcation-kjar in business-applcation then start it in business-applcation-service using "processService.startProcess(deploymentId, processId, params); ... etc" in easiest way.
You can have deployment descriptor defined on server level as well if that is just for testing. 
See this example handler https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-spring-boot/kie-spring-boot-samples/jbpm-spring-boot-sample-basic/src/test/java/org/jbpm/springboot/samples/handlers/WidWorkItemHandler.java that is automatically registered based on the wid annotation. Though if you handler requires more advanced creation like injecting beans then the best way is to create producer method (annotated with @Bean) and simply return fully initiated bean of the handler class 

Maciej
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-setup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-setup/ca45e983-d771-4ea4-afd7-ca661762f21f%40googlegroups.com.

Mohammed Abdulkareem

unread,
Nov 25, 2019, 6:40:22 AM11/25/19
to jBPM Setup
Thanks to feedback!
I wrote this configuration class

@Configuration
@ConditionalOnClass({ KModuleDeploymentService.class })
@EnableConfigurationProperties({ JBPMProperties.class, DataSourceProperties.class })
public class AppConfig {
.
.
protected static final String PERSISTENCE_UNIT_NAME = "org.jbpm.domain";
@Bean
public WorkItemHandler jpaWorkItemHandler() {
return new JPAWorkItemHandler(PERSISTENCE_UNIT_NAME);
}
.
.
}

The error now when i am starting the process is:

[Near : {... new org.jbpm.process.workitem.jpa. ....}]
                 ^
[Line: 1, Column: 5]] with root cause

javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.domain


I tried to find which Persistence provider that business-application-service by default uses
I found this:

org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider

I tried to change it to org.hibernate.jpa.HibernatePersistenceProvider like this:

@Bean
@ConditionalOnMissingBean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaProperties jpaProperties) {
        .
        .
        factoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
        .
        .

}

But I got the same error

Note: I am using this CRUD operations on "person" entity at "jbpm" main database.

Am Sonntag, 3. November 2019 10:48:29 UTC+1 schrieb Maciej Swiderski:


Wiadomość napisana przez Mohammed Abdulkareem <mohammed....@healthcubator.com> w dniu 31.10.2019, o godz. 00:24:

Maciej
Reply all
Reply to author
Forward
0 new messages