Just to give it code example, here is how you would do for a HibernateLongInstance:
First, You have a hibernate entity with id of type Long and a hibernate mapping to your
class properly loaded in the same session as JBPM mappings. The mapping:
<class name="mypackage.MyEntity" table="SAMPLE_ENTITY">
| <id name="id" column="id" unsaved-value="0"
type="java.lang.Long">
| <generator class="native"/>
| </id>
| ...
| </class>
Then you use a HibernateLongInstance to wrap your entity and store it as any other JBPM
variable:
...
| // create my entity an wrap it with HibernateLongInstance
| MyEntity ent = new MyEntity();
| HibernateLongInstance entWrapper = new HibernateLongInstance();
| envWrapper.setObject(ent);
|
| // store it to root token context
| ContextInstance contextInstance = (ContextInstance)
| token.getProcessInstance().getInstance(ContextInstance.class);
| contextInstance.setVariable("my-entity-variable", entWrapper);
| ...
To access it later, just get the wrapped object and class cast it back to your entity:
...
| ContextInstance contextInstance = (ContextInstance)
| token.getProcessInstance().getInstance(ContextInstance.class);
| HibernateLongInstance entWrapper = (HibernateLongInstance)
| contextInstance.getVariable("my-entity-variable");
| MyEntity entData = (MyEntity)entWrapper.getObject();
| ...
That's it!
A warning though: The default configuration has Serializable type mapped before Hibernate
and EJB types. That means that if your entity class implements java.io.Serializable it
will get serialized as a byte array and not as a Hibernate entity. To avoid this behavior,
re-order the types in jbpm.varmapping.xml.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009404#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...