我是学生,我有一个嵌入了 jbpm 5 框架的 Web 应用程序(这个问题不是关于任何 jbpm 5 相关主题,而是关于 JPA 和 MySql 数据库上 jbpm 类的持久性)。此 Web 应用程序应在配置了 Bitronix 事务管理器的 tomcat 7 上运行。JPA 用于使用 2 个 persistence-units 来持久化 jbpm 相关类,这里是 persistance.xml :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/testDS1</jta-data-source>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<class>org.jbpm.task.Task</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Attachment</class>
<class>org.jbpm.task.I18NText</class>
<class>org.jbpm.task.SubTasksStrategy</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Escalation</class>
<class>org.jbpm.task.Reassignment</class>
<class>org.jbpm.task.Notification</class>
<class>org.jbpm.task.BooleanExpression</class>
<class>org.jbpm.task.User</class>
<class>org.jbpm.task.PeopleAssignments</class>
<properties>
<!-- H2 dialect -->
<!--<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>-->
<!-- Oracle dialect
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
-->
<!-- mysql dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
</properties>
</persistence-unit>
<persistence-unit name="org.jbpm.task">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.jbpm.task.Attachment</class>
<class>org.jbpm.task.Content</class>
<class>org.jbpm.task.BooleanExpression</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Delegation</class>
<class>org.jbpm.task.Escalation</class>
<class>org.jbpm.task.Group</class>
<class>org.jbpm.task.I18NText</class>
<class>org.jbpm.task.Notification</class>
<class>org.jbpm.task.EmailNotification</class>
<class>org.jbpm.task.EmailNotificationHeader</class>
<class>org.jbpm.task.PeopleAssignments</class>
<class>org.jbpm.task.Reassignment</class>
<class>org.jbpm.task.Status</class>
<class>org.jbpm.task.Task</class>
<class>org.jbpm.task.TaskData</class>
<class>org.jbpm.task.SubTasksStrategy</class>
<class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
<class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
<class>org.jbpm.task.User</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<properties>
<!-- sample H2 configuration -->
<!--
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.url" value="jdbc:h2:mem:droolsflow" />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="sdfsdf"/> -->
<!-- Sample Oracle Configuration
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@oraclehost:1521:jbpm5" />
<property name="hibernate.connection.username" value="user"/>
<property name="hibernate.connection.password" value="password"/>
-->
<!-- Sample mysql Configuration -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm5webexpl" />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="sdfsdf"/>
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
持久性工作得很好,我让数据库填充了数据。所以现在我想从该数据中读取数据,特别是从一个名为“organizationalentity”的表中读取,该表是由数据库上的持久性工作生成的,即使该表对应的 java 类没有在persistance.xml上声明(这对我来说很奇怪,但表是创建的并包含数据!!但是当我遇到异常时我自己做了,但这不是解决方案)。该表的 java 类实际上存在于一个 maven 引用的 jar 中,而不是我自己编写的包中(这就是我无法在其上添加一些 NamedQueries 的原因,因为这个类是一个 .class 而不是.java ..)
所以我在我的类路径中添加了这个新的 OrganizationalEntityDao.java 类:
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jbpm.task.OrganizationalEntity;
public class OrganizationalEntityDao {
@PersistenceContext(unitName = "org.jbpm.task")
static EntityManager em;
public static OrganizationalEntity readById(int id) {
return em.find(OrganizationalEntity.class,id);
}
}
当我运行我的应用程序时,我收到了这个错误:
javax.el.ELException: /index.xhtml @142,119 listener="#{processBean.requestPage}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:450)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
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:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at entities.dao.OrganizationalEntityDao.readById(OrganizationalEntityDao.java:20)
at entities.beans.ProcessBean.requestPage(ProcessBean.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 27 more
我应该说我想知道在 tomcat 上使用 JPA 来持久化实体(作为 EJB 工作)。我没有使用 JDBC 来完成这项工作,因为 JPA 已经被使用了。伙计们,有什么想法吗?干杯。