Hi, all:
I'm a newbie to Drools.
I'm trying to restore stateful knowledge session using JPAKnowledgeService after restarting server.
In my rules I use Drools Fusion's Sliding Length Window to processing events. Below is a sample:
package com.sample
import com.sample.Event;
import java.util.List;
declare Event
        @role(event)
end
rule "test"
when
                $list : List() from collect(Event() over window: length(2))
         then
                System.out.println("list size:" + $list.size());
end
And I have done what should be done according to the manual reference. When I running my test
case below:
@Test
        public void test_persistedsession() {
                KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
                loadDRL(kbase);
                
                Environment env = KnowledgeBaseFactory.newEnvironment();
                env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" ) );
                env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
                
                //create a persisted statefulknowledgesession
                StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
                ksession.insert(new Event());
                ksession.fireAllRules();
                
                ksession.insert(new Event());
                ksession.fireAllRules();
                
                //reload the persisted session
                ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase, null, env);
                
                ksession.insert(new Event());
                ksession.fireAllRules();
                
                ksession.insert(new Event());
                ksession.fireAllRules();
        }
Then I found that the result is:
Hibernate: insert into SessionInfo (id, lastModificationDate, rulesByteArray, startDate, OPTLOCK) values (null, ?, ?, ?, ?)
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
<b>list size:1</b>
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
<b>list size:2</b>
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
<b>list size:3</b>
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
<b>list size:4</b>
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
As I have declared that the length of window is 2, how can the size of list increase to 3, 4 and more?
I am using the 5.2.0 final. May be I have missed something, please help me.
Any help will be appreciated.
        
        
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://drools.46999.n3.nabble.com/persisted-StatefulKnowledgeSession-failed-to-maintain-the-length-of-Sliding-window-tp4019696.html">persisted StatefulKnowledgeSession failed to maintain the length of Sliding window?</a><br/>
Sent from the <a href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html">Drools: User forum mailing list archive</a> at Nabble.com.<br/>