<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    jBPM5 and ObjectMarshallingStrategy
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/mnorsic">Miljenko Norsic</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/631373#631373">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi All,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a question about persistent JPA object marshalling strategies.</p><p>I'd like to use jBPM5 in an already built project that uses custom ORM mapper (something similar to Hibernate, but uses its own persistency mechanism).</p><p>Ideally, I'd love to use somethning similar to JPAPlaceholderResolverStrategy, to force jBPM5 to store only class name and its primary key.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So I've started to look into jBPM5 code to see where can I plug in my persistency mechanism, and found that I have to add my custom object marshaller into enviroment:</p><pre class="jive-pre"><code class="jive-code jive-java">env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, <font color="navy"><b>new</b></font> ObjectMarshallingStrategy[] <font color="navy">{</font>
<font color="navy"><b>new</b></font> MyCustomMarshallingStrategy(env),
 <font color="navy"><b>new</b></font> JPAPlaceholderResolverStrategy(env),
 <font color="navy"><b>new</b></font> SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) <font color="navy">}</font>);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So, now my custom resolver is used in marshalling and unmarshalling to write and read object reference into database, instead storing whole serialized object, and that seems OK.</p><p>But my custom Java objects do not implement Serializable, and I've spotted the following error:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">java.lang.RuntimeException: Unable to get session snapshot
 at org.drools.persistence.SessionMarshallingHelper.getSnapshot(SessionMarshallingHelper.java:75)
 at org.drools.persistence.info.SessionInfo.update(SessionInfo.java:81)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:23)
 at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:80)
 at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:65)
 at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:41)
 at org.hibernate.event.def.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:330)
 at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:270)
 at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151)
 at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
 at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
 at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
 at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
 ... 28 more
Caused by: java.io.NotSerializableException: hr.mnorsic.test.bo.SomeClass
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
 at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
 at java.util.HashMap.writeObject(HashMap.java:1001)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
 at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
 at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
 at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
 at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
 at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
 at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
 at java.util.ArrayList.writeObject(ArrayList.java:570)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
 at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
 at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
 at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
 at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
 at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
 at org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy.write(SerializablePlaceholderResolverStrategy.java:53)
 at org.drools.marshalling.impl.OutputMarshaller.writeFactHandle(OutputMarshaller.java:305)
 at org.drools.marshalling.impl.OutputMarshaller.writeFactHandle(OutputMarshaller.java:325)
 at org.drools.marshalling.impl.OutputMarshaller.writeFactHandles(OutputMarshaller.java:267)
 at org.drools.marshalling.impl.OutputMarshaller.writeSession(OutputMarshaller.java:107)
 at org.drools.marshalling.impl.DefaultMarshaller.marshall(DefaultMarshaller.java:136)
 at org.drools.persistence.SessionMarshallingHelper.getSnapshot(SessionMarshallingHelper.java:72)
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My class (SomeClass) does not implement Serializable, but it seems weird that jBPM is trying to use SerializablePlaceholderResolverStrategy to store knowledge session info instead my own persistency strategy.</p><p>Digging down into jBPM5 code, I have found that RuleFlowProcessInstance object is serialized by using SerializablePlaceholderResolverStrategy, and that object contains VariableScopeInstance object (in a subContextInstances HashMap).</p><p>And VariableScopeInstance contains process instance variables, so they are serialized into a byte array instead using JPA strategy (or my own strategy, doesn't matter).</p><p>At the same time, process instance is stored correctly (it uses JPA resolver strategy and stores only a reference to an object stored in a database).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I think this is not correct, as process instance contains a reference to an object a database, and session info contains whole serialized objects?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Could please someone from jBPM team review my observation?</p><p>My guess is that when RuleFlowProcessInstance is persisted, subContextInstances Map should be examined, and for each element a query to a objectMarshallingStrategyStore accept() method should be called to determine the correct persistence strategy.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks,</p><p>Miljenko</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>P.S. forgot to mention: my process contains rule task and custom tasks (controlled by custom work item handler).</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/631373#631373">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>