JBPM 6.4에 새 저장소와 새 프로젝트를 만들었습니다. 프로젝트 내부 나는 persistence.xml
생성 : 프로젝트의 JBPM 6.4 지속 유닛
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<persistence-unit name="demox:com.prueba:1.0" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
<class>demox.com.prueba.Estudiante</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<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.id.new_generator_mappings" value="false"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
또한 나는 persistible 객체 (
@Entity
장식 POJO)를 정의했다.
이제 스크립트 작업이 하나만있는 간단한 프로세스가 있습니다.
하지만 내 DB에 프로세스를 배치 할 때 Student
테이블이 만들어집니다 ...
package demox.com.prueba;
/**
* This class was automatically generated by the data modeler tool.
*/
@javax.persistence.Entity
public class Estudiante implements java.io.Serializable
{
static final long serialVersionUID = 1L;
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO, generator = "ESTUDIANTE_ID_GENERATOR")
@javax.persistence.Id
@javax.persistence.SequenceGenerator(name = "ESTUDIANTE_ID_GENERATOR", sequenceName = "ESTUDIANTE_ID_SEQ")
private java.lang.Long id;
@org.kie.api.definition.type.Label(value = "name")
private java.lang.String name;
public Estudiante()
{
}
public java.lang.Long getId()
{
return this.id;
}
public void setId(java.lang.Long id)
{
this.id = id;
}
public java.lang.String getName()
{
return this.name;
}
public void setName(java.lang.String name)
{
this.name = name;
}
public Estudiante(java.lang.Long id, java.lang.String name)
{
this.id = id;
this.name = name;
}
}
그래서 질문은 :이 scriptTask
내부에 들어 가지 방법이 EntityManger
에 대한 참조가이 POJO를 지속하기 ?
내가 시도 :
demox.com.prueba.Estudiante est=new demox.com.prueba.Estudiante();
String pu="demox:com.prueba:1.0";
//javax.persistence.EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory(pu);
javax.persistence.EntityManagerFactory emf = (javax.persistence.EntityManagerFactory) kcontext.getKnowledgeRuntime().getEnvironment()
.get(org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY); # tried also EnvironmentName.CMD_SCOPED_ENTITY_MANAGER
System.out.println("Entity manager " + emf);
emf.persist(est);
그러나이 코드를 사용 할 때의 EntityManager는 알 수없는 jBPM을 지속성 단위 나의 POJO 클래스를 포함하지 않는 내 퍼시스턴스 유닛 (데모)에 인스턴스에 대한 참조 (이다 실재).
내 스크립트 작업에서이 퍼시스턴스 유닛에 어떻게 액세스 할 수 있습니까?