Jbpm 6.4 pesistence unit on project
dacopan Aug 8, 2016 9:50 AM
|
I created a new repository and a new Project in JBPM 6.4 Inside project I created a persistence.xml <?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> Also I defined a persistible object (pojo decorated with Now I have a simple process with only a one script task But when I deployed the process in my DB the Student Table is created...
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;
}
}
So the question is how get inside this scriptTask the reference to this EntityManger to persist this pojo? I tried:
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);
But when used this code the EntityManager is a reference to a jbpm persistence unit not a instance to my persistence unit(demo) which don't contain my pojo class (unknown Entity) so how can acces to this persistence unit in my script task? |