Drools SubProcess out mapping failed - what am I doing wrong? - subprocess

I created two "Hello World" processes to give the subProcess nodes a whirl. I'm having trouble getting output from the subProcess back to the main process. I'm hoping someone can enlighten me on what I'm doing wrong as I can't find any documentation or examples that shed light on why mine doesn't work.
In my main process, I have the following (note that I've snipped headers, footers, and the positional x, y, height, width attributes):
... snip...
<header>
<variables>
<variable name="name" >
<type name="org.drools.process.core.datatype.impl.type.StringDataType" />
<value>World</value>
</variable>
<variable name="length" >
<type name="org.drools.process.core.datatype.impl.type.IntegerDataType" />
<value>0</value>
</variable>
</variables>
</header>
... snip...
<subProcess id="4" name="SubHello"
processId="subhello" waitForCompletion="true" >
<mapping type="in" from="name" to="name" />
<mapping type="out" from="length" to="length" />
</subProcess>
... snip...
And here is the simple subhello SubProcess, which simply takes the input and prints it out, and then gets the input length to return it back out:
... snip...
<header>
<variables>
<variable name="name" >
<type name="org.drools.process.core.datatype.impl.type.StringDataType" />
<value></value>
</variable>
<variable name="length" >
<type name="org.drools.process.core.datatype.impl.type.IntegerDataType" />
<value></value>
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start" />
<end id="2" name="End" />
<actionNode id="3" name="Action" >
<action type="expression" dialect="mvel" >
System.out.println(name + ", " + length + ", in SubProcess, before");
length = name.length;
System.out.println(length + ", in SubProcess, after");
</action>
</actionNode>
</nodes>
... snip...
This is as per how I interpreted the doc and examples. The needed variables are declared on both the main process and the subprocess, then just use the subProcess in/out mapping elements to set the from and to attributes.
The problem is.... while name got passed in to the subProcess without issue, trying to get length back to the main process failed. The length in the subProcess was successfully modified. But on exit, length in the main process did not change.
What am I doing wrong? Pointers and explanations are much appreciated. Thanks.

The problem is that your action does not change the length variable. It merely changes the local variable length inside your action. To change the value of the variable, use kcontext.setVariable("length", name.length());
You should also update to the latest Drools 5.1 M1 release, as that includes a fix for an issue with out mappings in case the subprocess is completely synchronous (as is the case in your example).
Kris Verlaenen

Related

SharePoint PnP - Adding fields to default view

I’m using the SharePoint PnP templates to deploy a list instance to SharePoint 2016. Is it possible to make the field “TheName” part of the default view or a particular view using an attribute?
Below I’ve set the “TheName” field attributes Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" but that has not resulted in “TheName” being part of the default view. Below is the xml for the list instance:
<pnp:ListInstance Title="Application" Description="" EnableAttachments="true" DocumentTemplate="" TemplateType="100" Url="Lists/Application" MinorVersionLimit="0" MaxVersionLimit="0" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-de22-43b2-a848-c05709900100" ContentTypesEnabled="true" EnableFolderCreation="true">
<pnp:ContentTypeBindings>
<pnp:ContentTypeBinding ContentTypeID="0x0109413FF39DA2049E08C8B9564402E3562" Default="true" />
</pnp:ContentTypeBindings>
<pnp:Fields>
<pnp:Field Type="Text" DisplayName="TheName" StaticName="TheName" Name="TheName" Default="true" ID="{db2beb10-5325-434d-a559-691e340a4fea}" Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" />
</pnp:Fields>
</pnp:Views>
</pnp:ListInstance>
I can explicitly create/set the default view to include “TheName” but then I end up having to list all the fields that are part of the list including the ones which come from a site content type. This can become a hassle to maintain. The below list instance xml displays “TheName” as part of the default view:
<pnp:ListInstance Title="Application" Description="" EnableAttachments="true" DocumentTemplate="" TemplateType="100" Url="Lists/Application" MinorVersionLimit="0" MaxVersionLimit="0" DraftVersionVisibility="0" TemplateFeatureID="00bfea71-de22-43b2-a848-c05709900100" ContentTypesEnabled="true" EnableFolderCreation="true">
<pnp:ContentTypeBindings>
<pnp:ContentTypeBinding ContentTypeID="0x0109413FF39DA2049E08C8B9564402E3562" Default="true" />
</pnp:ContentTypeBindings>
<pnp:Fields>
<pnp:Field Type="Text" DisplayName="TheName" StaticName="TheName" Name="TheName" Default="true" ID="{db2beb10-5325-434d-a559-691e340a4fea}" Viewable="true" ShowInDisplayForm="true" ShowInViewForms="true" />
</pnp:Fields>
<pnp:Views>
<View DisplayName="All Items">
<ViewFields>
<FieldRef Name="TheName" />
<FieldRef Name="Title" />
<FieldRef Name="ApplicationId" />
<FieldRef Name="Case" />
</ViewFields>
</View>
</pnp:Views>
</pnp:ListInstance>

Hibernate exception javassist

I need some help as I'm stumped on an Hibernate 4/Struts 2 project. This is my first Hibernate 4 (4.3.11) project, as I worked for years with Hibernate 3. The database is MySQL 5.
All mapping classes were produced with Hibernate Tools provided by JBoss Tools 4.3.5, on Eclipse Mars 2. No problem was encountered, it worked fine.
But when testing, I faced this exception :
2017-02-16 17:23:45 ERROR Dispatcher:38 - Exception occurred during processing request: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
java.lang.ClassCastException: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:75)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:771)
I read that post but I don't understand what's happening.
Two classes are involved : Salle and Ville. Here's the Hibernate XML files : Salle.hbm.xml & Ville.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2 f?vr. 2017 11:28:16 by Hibernate Tools 4.3.5.Final -->
<hibernate-mapping>
<class name="metier.Salle" table="salle" catalog="aevbadherents" optimistic-lock="version">
<id name="idSalle" type="int">
<column name="idSALLE" />
<generator class="assigned" />
</id>
<many-to-one name="ville" class="metier.Ville" fetch="select">
<column name="idVilleSalle" />
</many-to-one>
<property name="adresse1" type="string">
<column name="Adresse1" length="80" />
</property>
<property name="adresse2" type="string">
<column name="Adresse2" length="80" />
</property>
<property name="description" type="string">
<column name="Description" length="500" />
</property>
<set name="courses" table="cours" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" not-null="true" />
</key>
<one-to-many class="metier.Cours" />
</set>
<set name="passagegrades" table="passagegrade" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" />
</key>
<one-to-many class="metier.Passagegrade" />
</set>
</class>
</hibernate-mapping>
The second file :
<hibernate-mapping>
<class name="metier.Ville" table="ville" catalog="aevbadherents" optimistic-lock="version">
<id name="idVille" type="int">
<column name="idVILLE" />
<generator class="assigned" />
</id>
<many-to-one name="departement" class="metier.Departement" fetch="select">
<column name="idDepartement" not-null="true" />
</many-to-one>
<property name="nom" type="string">
<column name="Nom" length="60" not-null="true" />
</property>
<property name="codepostal" type="string">
<column name="codepostal" length="6" not-null="true" />
</property>
<property name="gpslat" type="string">
<column name="GPSLat" length="12" not-null="true" />
</property>
<property name="gpslon" type="string">
<column name="GPSLon" length="12" not-null="true" />
</property>
<set name="adherentsForIdVilleResid" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleResid" />
</key>
<one-to-many class="metier.Adherent" />
</set>
<set name="clubs" table="club" inverse="true" lazy="true" fetch="select">
<key>
<column name="idville" not-null="true" />
</key>
<one-to-many class="metier.Club" />
</set>
<set name="salles" table="salle" inverse="true" lazy="true" fetch="select">
<key>
<column name="idVilleSalle" />
</key>
<one-to-many class="metier.Salle" />
</set>
<set name="adherentsForIdVilleNais" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleNais" />
</key>
<one-to-many class="metier.Adherent" />
</set>
</class>
</hibernate-mapping>
I read that this exception may be caused by a JAR conflict, but I did not find anything.I don't use Maven (maybe I should ?), so let me show you the JARs included :
antlr-2.7.7.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.2-javadoc.jar
commons-logging-1.2.jar
dom4j-1.6.1.jar
freemarker-2.3.19.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.11.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
log4j-1.2.15.jar
mysql-connector-java-5.1.40-bin.jar
ognl-3.0.6.jar
struts2-core-2.3.15.3.jar
truc.txt
xwork-core-2.3.15.3.jar
Please help me, as I'm stumped...
One of the possible cause for this problem is that you have in your classpath several versions of the same class.
I have been looking in java2s.com and, none of the jar you listed, seems to contain the class javassist.util.proxy.Proxy, so I will try to find if any other jar contains that class using jarscan with the following command:
jarscan -d PATH_TO_YOUR_CLASSPATH_DIR -j javassist.util.proxy.Proxy
You can download jarscan from here https://java.net/projects/jarscan/downloads
If you found that several packages contains the same class, you are done.
Malaguna,
Thanks for your help. Here's the result of jarscan :
D:\temp\java\jarscan>jarscan -j javassist.util.proxy.Proxy
......................
+javassist-3.18.1-GA.jar
javassist-3.18.1-GA.jar\javassist/util/proxy/Proxy.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$1.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$2.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$3.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ClassLoaderProvide
r.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$Find2MethodsArgs.c
lass
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ProxyDetails.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$UniqueName.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObject.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectInputStream.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectOutputStream.class
----------------------------------------------
Scanned archives: 22
Errors: 0
Archives with hits: 12
So, it means that no other jar contains that class.

PropelORM+PostgreSQL: How do I define an SQL-like CHECK constraint on a column in 'schema.xml'?

A little snippet of a database schema I'm trying to define in my "schema.xml" file:
<table name="hotelroom" phpName="hotelroom">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="room_number" type="varchar" size="10" required="true" />
<column name="price" type="numeric" defaultValue="1000" required="true" />
<unique>
<unique-column name="room_number" />
</unique>
</table>
In PostgreSQL for that "price" column I would've written CHECK (price > 0::numeric),but I can't seem to find any way to achieve this here.I've checked the documentation (http://propelorm.org/documentation/reference/schema.html), but couldn't find anything on this.
Thank you for the time.
You're using v1, but from the doc link above, looks like you're using v2,
I think you're looking for the GreaterThan which is only available from v2 onwards.
<behavior name="validate">
<parameter name="rule1" value="{column: price, validator: GreaterThan, options: {value: 0, message=Price is not valid}}" />
</behavior>

Sakai Hibernate lazy initialize

I'm having some issues building my database. I have this two hbm mappings:
<class name="br.unicamp.iel.model.Module" table="readinweb_modules">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<many-to-one name="course" class="br.unicamp.iel.model.Course"
column="course_id" fetch="select" />
<property name="position" type="integer" />
<property name="module_grammar" type="text" />
</class>
<class name="br.unicamp.iel.model.Course" table="readinweb_courses">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<property name="title" length="255" not-null="true" type="string" />
<property name="idiom" length="255" not-null="true" type="string" />
<property name="description" type="text" />
<set name="courseModules" table="readinweb_modules"
inverse="true" lazy="true" fetch="select">
<key column="id" not-null="true" />
<one-to-many class="br.unicamp.iel.model.Module" />
</set>
</class>
and when I try to access data on my logic bean as:
List modules = new ArrayList(dao.findById(Course.class,
course).getCourseModules());
it gives me a
org.hibernate.LazyInitializationException: failed to lazily initialize
a collection of role: br.unicamp.iel.model.Course.courseModules, no
session or session was closed
We need to see the complete code of the
List modules = new ArrayList(dao.findById(Course.class, course).getCourseModules())
Do you open and close a Session (or a EntityManager) inside the dao.findById method? The session must still be open to resolve lazy relationships

JPA Secondary Table XML Config

I am working on a project where I need to store an Entity, which is unmodifiable (from library), so I am using XML entity mappings entity object is like:
public abstract class BaseModel{
Long uid;
//getters/setters
}
public abstract class LocaleBaseModel{
String locale;
//Other properties, getter/setters
}
public class Article extends LocaleBaseModel{
private Long authorId;
privaet String text;
//Other properties
}
<mapped-superclass class="package.BaseModel">
<attributes>
<id name="uid">
<column name="UID" nullable="false" />
<generated-value strategy="AUTO" />
</id>
</attributes>
</mapped-superclass>
<mapped-superclass class="package.LocaleBaseModel">
<secondary-table name="STableName">
<primary-key-join-column name="MID" referenced-column-name="UID" />
</secondary-table>
<attributes>
<basic name="locale">
<column name="LOCALE" updatable="false" nullable="false" />
</basic>
<basic name="text">
<column name="Text" updatable="false" nullable="false" table="STableName" />
</basic>
</attributes>
</mapped-superclass>
<entity class="package.child.Article" name="Hadith">
<table name="TableName" />
<attributes>
</attributes>
</entity>
but as soon as I add <secondarytable> I get an error which is quiet explanatory in itself:
14:58:47,379 ERROR ErrorLogger:57 - Error parsing XML (2) :
cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element
'entity-mappings' is not valid with respect to the corresponding
attribute use. Attribute 'version' has a fixed value of '1.0'.
14:58:47,379 ERROR ErrorLogger:57 - Error parsing XML (2) :
cvc-complex-type.2.4.a: Invalid content was found starting with
element 'element-collection'. One of
'{"http://java.sun.com/xml/ns/persistence/orm":basic,
"http://java.sun.com/xml/ns/persistence/orm":version,
"http://java.sun.com/xml/ns/persistence/orm":many-to-one,
"http://java.sun.com/xml/ns/persistence/orm":one-to-many,
"http://java.sun.com/xml/ns/persistence/orm":one-to-one,
"http://java.sun.com/xml/ns/persistence/orm":many-to-many,
"http://java.sun.com/xml/ns/persistence/orm":embedded,
"http://java.sun.com/xml/ns/persistence/orm":transient}' is expected.
14:58:47,379 ERROR ErrorLogger:57 - Error parsing XML (2) :
cvc-complex-type.2.4.a: Invalid content was found starting with
element 'secondary-table'. One of
'{"http://java.sun.com/xml/ns/persistence/orm":description,
"http://java.sun.com/xml/ns/persistence/orm":id-class,
"http://java.sun.com/xml/ns/persistence/orm":exclude-default-listeners,
"http://java.sun.com/xml/ns/persistence/orm":exclude-superclass-listeners,
"http://java.sun.com/xml/ns/persistence/orm":entity-listeners,
"http://java.sun.com/xml/ns/persistence/orm":pre-persist,
"http://java.sun.com/xml/ns/persistence/orm":post-persist,
"http://java.sun.com/xml/ns/persistence/orm":pre-remove,
"http://java.sun.com/xml/ns/persistence/orm":post-remove,
"http://java.sun.com/xml/ns/persistence/orm":pre-update,
"http://java.sun.com/xml/ns/persistence/orm":post-update,
"http://java.sun.com/xml/ns/persistence/orm":post-load,
"http://java.sun.com/xml/ns/persistence/orm":attributes}' is expected.
I have following on path, with others from spring 3.0.5
hibernate-entitymanager-3.6.2
hibernate-jpa-2.0-api
hibernate-core-3.6.2.Final
according to the orm-schema
the secondary-table elements likes to be placed
withing the
entity element after the table tag
<pre> alike <entity>
<table/>
<secondary-table/>
...
agreed the error message is noisy but that is
the glorious schema spec.
ys.