Re: [rules-users] Persistence in Drools 6

2014-09-11 Thread dush...@gmail.com
Hi Jean Philippe,

I managed to get around using kie-spring with KieScanner integration. if you
use exact configuration as below you will be able to setup persistence,
scanner together with spring 6.1.0. 





LATEST*" 
/>



defaultKieBase*">
defaultKieSession*">



















In a separate bean execute below code to set-up scanner (can use
init-method).

ReleaseId releaseId = (ReleaseId)
applicationContext.getBean("kReleaseId");
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner kieScanner = ks.newKieScanner(kieContainer);
//kieScanner.start(5000L);
kieScanner.scanNow();


Note highlighted text snippets. use them as is.  Caveat is , when you set-up
kbase with a release id and kiecontainer, default  beans created by spring
would be ignored. instead   container would create default kbase and a
ksession(s)(stateful,stateless) for you. those names should be included as
highlighted.

This is totally a workaround I found while debugging and yet to test if
scanner functionality is working properly.



--
View this message in context: 
http://drools.46999.n3.nabble.com/rules-users-Persistence-in-Drools-6-tp4029655p4030761.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Persistence in Drools 6

2014-05-28 Thread Steinmetz, Jean-Philippe
Hi Charles,

Yes I am using a KieScanner to look for updates. Since I am using Spring I
had to wrap it so that it could be properly initialized and started as a
bean. I didn't include that bit in my original post as it didn't seem
relevant to the problem at hand.

The other reason why I decided to use the bean notation instead of the kie
namespace is so that I could reference the created session as a bean that
could be injected as a property to another bean (the thread class that sets
up the session for my application and actually calls fireAllRules). Perhaps
I was not doing it right but Spring wasn't recognizing anything in the
 tags as a bean I could reference.

In any case, my approach should be identical to setting up the session in
Java directly as follows.

KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId("mygroup", "myartifact",
"version");
KieContainer kContainer = kieServices.newKieContainer(releaseId);
Environment env = kieServices.newEnvironment();
env.set(ENTITY_MANAGER_FACTORY, entityManagerFactory);
env.set(TRANSACTION_MANAGER, transactionManager);
KieSession kSession = kContainer.newKieSession(env);

This as far as I've read is exactly how the documentation recommends it be
done. It just doesn't actually work for some reason or another.

Jean-Philippe


On Tue, May 27, 2014 at 11:42 PM, Charles Moulliard wrote:

> Hi Jean-Philippe,
>
> To pickup new updates, then you should use KieScanner (part of kie-ci
> project) which allows you to do incremental build if a new kjar has been
> published/released. Here is an example :
> https://github.com/droolsjbpm/drools/blob/master/kie-ci/src/test/java/org/kie/scanner/KieScannerIncrementalCompilationTest.java
>
> Regards,
>
>
>
> On Tue, May 27, 2014 at 7:38 PM, Steinmetz, Jean-Philippe <
> jpsteinm...@theworkshop.us.com> wrote:
>
>> Hi Charles,
>>
>> Thanks for your reference. I had tried using kie-spring but was unable to
>> use it as it currently does not support creating sessions from a release id
>> and container. I did this in order to be able to pick up on updates to the
>> kjar from maven while the application is running the same way it used to
>> work in Drools 5. Has anyone else with similar needs to mine gotten
>> persistence working?
>>
>> Jean-Philippe
>>
>>
>> On Thu, May 22, 2014 at 11:23 PM, Charles Moulliard wrote:
>>
>>> Hi Jean Philippe,
>>>
>>> I have recently created a project to persist bpmn process using Spring &
>>> JPA / Hibernate. This config is working using kie-spring
>>>
>>>
>>> https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml
>>>
>>> Regards,
>>>
>>> Charles
>>>
>>>
>>> On Thu, May 22, 2014 at 8:00 PM, Steinmetz, Jean-Philippe <
>>> jpsteinm...@theworkshop.us.com> wrote:
>>>
 Hello All,

 I am trying to set up persistence for a standalone Drools (6.0.1.Final)
 application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via
 Spring (4.0.3.RELEASE).

 On the persistence side everything appears to be set up correctly. For
 my Drools session I use a KieContainer to create a new stateful session
 using an environment set up with the EntityManagerFactory and
 TransactionManager set. The problem that I am experiencing however is that
 nothing is getting persisted to the database. I have poured over the docs
 at least two dozen times and searched the net for anything related.

 Here is what my Spring context file looks like when creating the Drools
 session...

 >>> factory-method="newReleaseId">
 
 
 
 
 >>> factory-method="newKieContainer">
 
 
 >>> factory-method="newEnvironment">
 
 
 
 >>> static-field="org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY"/>
 
 
 
 >>> static-field="org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER"/>
 
 
 
 
 
 >>> factory-method="newKieSession">
 
  

 Since the application is standalone I execute fireAllRules on the
 session at a regular interval (I use this instead of fireUntilHalt as it
 dramatically reduces the CPU load on the machine). With each call I wrap it
 in a transaction. Thus, the code looks as follows:

 while (!Thread.currentThread().isInterrupted()) {
 // Start a new transaction
 UserTransaction utx = utx = (UserTransaction)new
 InitialContext().lookup("java:comp/UserTransaction");
utx.begin();

 // Tick the session
 kSession.fireAllRules();

 // Close the transaction
 utx.comm

Re: [rules-users] Persistence in Drools 6

2014-05-27 Thread Charles Moulliard
Hi Jean-Philippe,

To pickup new updates, then you should use KieScanner (part of kie-ci
project) which allows you to do incremental build if a new kjar has been
published/released. Here is an example :
https://github.com/droolsjbpm/drools/blob/master/kie-ci/src/test/java/org/kie/scanner/KieScannerIncrementalCompilationTest.java

Regards,



On Tue, May 27, 2014 at 7:38 PM, Steinmetz, Jean-Philippe <
jpsteinm...@theworkshop.us.com> wrote:

> Hi Charles,
>
> Thanks for your reference. I had tried using kie-spring but was unable to
> use it as it currently does not support creating sessions from a release id
> and container. I did this in order to be able to pick up on updates to the
> kjar from maven while the application is running the same way it used to
> work in Drools 5. Has anyone else with similar needs to mine gotten
> persistence working?
>
> Jean-Philippe
>
>
> On Thu, May 22, 2014 at 11:23 PM, Charles Moulliard wrote:
>
>> Hi Jean Philippe,
>>
>> I have recently created a project to persist bpmn process using Spring &
>> JPA / Hibernate. This config is working using kie-spring
>>
>>
>> https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml
>>
>> Regards,
>>
>> Charles
>>
>>
>> On Thu, May 22, 2014 at 8:00 PM, Steinmetz, Jean-Philippe <
>> jpsteinm...@theworkshop.us.com> wrote:
>>
>>> Hello All,
>>>
>>> I am trying to set up persistence for a standalone Drools (6.0.1.Final)
>>> application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via
>>> Spring (4.0.3.RELEASE).
>>>
>>> On the persistence side everything appears to be set up correctly. For
>>> my Drools session I use a KieContainer to create a new stateful session
>>> using an environment set up with the EntityManagerFactory and
>>> TransactionManager set. The problem that I am experiencing however is that
>>> nothing is getting persisted to the database. I have poured over the docs
>>> at least two dozen times and searched the net for anything related.
>>>
>>> Here is what my Spring context file looks like when creating the Drools
>>> session...
>>>
>>> >> factory-method="newReleaseId">
>>> 
>>> 
>>> 
>>> 
>>> >> factory-method="newKieContainer">
>>> 
>>> 
>>> >> factory-method="newEnvironment">
>>> 
>>> 
>>> 
>>> >> static-field="org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY"/>
>>> 
>>> 
>>> 
>>> >> static-field="org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER"/>
>>> 
>>> 
>>> 
>>> 
>>> 
>>> >> factory-method="newKieSession">
>>> 
>>>  
>>>
>>> Since the application is standalone I execute fireAllRules on the
>>> session at a regular interval (I use this instead of fireUntilHalt as it
>>> dramatically reduces the CPU load on the machine). With each call I wrap it
>>> in a transaction. Thus, the code looks as follows:
>>>
>>> while (!Thread.currentThread().isInterrupted()) {
>>> // Start a new transaction
>>> UserTransaction utx = utx = (UserTransaction)new
>>> InitialContext().lookup("java:comp/UserTransaction");
>>>utx.begin();
>>>
>>> // Tick the session
>>> kSession.fireAllRules();
>>>
>>> // Close the transaction
>>> utx.commit();
>>>
>>> // Sleep so that other applications can use the CPU
>>> try {
>>> Thread.sleep(1);
>>> } catch (InterruptedException e) {
>>> // When our sleep is interrupted it's because the
>>> executor wants us to shut down.
>>> Thread.currentThread().interrupt();
>>> }
>>> }
>>>
>>> When I inspect kSession in the debugger I can see the environment is
>>> properly set. I have tried digging down into the execute a bit but can't
>>> find any point at which the TransactionManager or EntityManagerFactory are
>>> used. As I said above I know Hibernate is set up correctly as well as
>>> Bitronix. I can see them working just fine in the logs and they definitely
>>> are hitting the database (and create tables for sessioninfo and
>>> workingmemory as they should). I just get nothing actually in the database
>>> stored, ever.
>>>
>>> Any help here is appreciated. It seems like it should work but it just
>>> doesn't.
>>>
>>> Thanks in advance,
>>>
>>> Jean-Philippe Steinmetz
>>>
>>>
>>> ___
>>> rules-users mailing list
>>> rules-users@lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>
>>
>>
>> --
>> Charles Moulliard
>> Apache Committer / Architect @RedHat
>> Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
>>
>>
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss

Re: [rules-users] Persistence in Drools 6

2014-05-27 Thread Steinmetz, Jean-Philippe
Hi Charles,

Thanks for your reference. I had tried using kie-spring but was unable to
use it as it currently does not support creating sessions from a release id
and container. I did this in order to be able to pick up on updates to the
kjar from maven while the application is running the same way it used to
work in Drools 5. Has anyone else with similar needs to mine gotten
persistence working?

Jean-Philippe


On Thu, May 22, 2014 at 11:23 PM, Charles Moulliard wrote:

> Hi Jean Philippe,
>
> I have recently created a project to persist bpmn process using Spring &
> JPA / Hibernate. This config is working using kie-spring
>
>
> https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml
>
> Regards,
>
> Charles
>
>
> On Thu, May 22, 2014 at 8:00 PM, Steinmetz, Jean-Philippe <
> jpsteinm...@theworkshop.us.com> wrote:
>
>> Hello All,
>>
>> I am trying to set up persistence for a standalone Drools (6.0.1.Final)
>> application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via
>> Spring (4.0.3.RELEASE).
>>
>> On the persistence side everything appears to be set up correctly. For my
>> Drools session I use a KieContainer to create a new stateful session using
>> an environment set up with the EntityManagerFactory and TransactionManager
>> set. The problem that I am experiencing however is that nothing is getting
>> persisted to the database. I have poured over the docs at least two dozen
>> times and searched the net for anything related.
>>
>> Here is what my Spring context file looks like when creating the Drools
>> session...
>>
>> > factory-method="newReleaseId">
>> 
>> 
>> 
>> 
>> > factory-method="newKieContainer">
>> 
>> 
>> > factory-method="newEnvironment">
>> 
>> 
>> 
>> > static-field="org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY"/>
>> 
>> 
>> 
>> > static-field="org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER"/>
>> 
>> 
>> 
>> 
>> 
>> > factory-method="newKieSession">
>> 
>>  
>>
>> Since the application is standalone I execute fireAllRules on the session
>> at a regular interval (I use this instead of fireUntilHalt as it
>> dramatically reduces the CPU load on the machine). With each call I wrap it
>> in a transaction. Thus, the code looks as follows:
>>
>> while (!Thread.currentThread().isInterrupted()) {
>> // Start a new transaction
>> UserTransaction utx = utx = (UserTransaction)new
>> InitialContext().lookup("java:comp/UserTransaction");
>>utx.begin();
>>
>> // Tick the session
>> kSession.fireAllRules();
>>
>> // Close the transaction
>> utx.commit();
>>
>> // Sleep so that other applications can use the CPU
>> try {
>> Thread.sleep(1);
>> } catch (InterruptedException e) {
>> // When our sleep is interrupted it's because the
>> executor wants us to shut down.
>> Thread.currentThread().interrupt();
>> }
>> }
>>
>> When I inspect kSession in the debugger I can see the environment is
>> properly set. I have tried digging down into the execute a bit but can't
>> find any point at which the TransactionManager or EntityManagerFactory are
>> used. As I said above I know Hibernate is set up correctly as well as
>> Bitronix. I can see them working just fine in the logs and they definitely
>> are hitting the database (and create tables for sessioninfo and
>> workingmemory as they should). I just get nothing actually in the database
>> stored, ever.
>>
>> Any help here is appreciated. It seems like it should work but it just
>> doesn't.
>>
>> Thanks in advance,
>>
>> Jean-Philippe Steinmetz
>>
>>
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
>
> --
> Charles Moulliard
> Apache Committer / Architect @RedHat
> Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
>
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Re: [rules-users] Persistence in Drools 6

2014-05-22 Thread Charles Moulliard
Hi Jean Philippe,

I have recently created a project to persist bpmn process using Spring &
JPA / Hibernate. This config is working using kie-spring

https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml

Regards,

Charles


On Thu, May 22, 2014 at 8:00 PM, Steinmetz, Jean-Philippe <
jpsteinm...@theworkshop.us.com> wrote:

> Hello All,
>
> I am trying to set up persistence for a standalone Drools (6.0.1.Final)
> application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via
> Spring (4.0.3.RELEASE).
>
> On the persistence side everything appears to be set up correctly. For my
> Drools session I use a KieContainer to create a new stateful session using
> an environment set up with the EntityManagerFactory and TransactionManager
> set. The problem that I am experiencing however is that nothing is getting
> persisted to the database. I have poured over the docs at least two dozen
> times and searched the net for anything related.
>
> Here is what my Spring context file looks like when creating the Drools
> session...
>
>  factory-method="newReleaseId">
> 
> 
> 
> 
>  factory-method="newKieContainer">
> 
> 
>  factory-method="newEnvironment">
> 
> 
> 
>  static-field="org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY"/>
> 
> 
> 
>  static-field="org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER"/>
> 
> 
> 
> 
> 
>  factory-method="newKieSession">
> 
>  
>
> Since the application is standalone I execute fireAllRules on the session
> at a regular interval (I use this instead of fireUntilHalt as it
> dramatically reduces the CPU load on the machine). With each call I wrap it
> in a transaction. Thus, the code looks as follows:
>
> while (!Thread.currentThread().isInterrupted()) {
> // Start a new transaction
> UserTransaction utx = utx = (UserTransaction)new
> InitialContext().lookup("java:comp/UserTransaction");
>utx.begin();
>
> // Tick the session
> kSession.fireAllRules();
>
> // Close the transaction
> utx.commit();
>
> // Sleep so that other applications can use the CPU
> try {
> Thread.sleep(1);
> } catch (InterruptedException e) {
> // When our sleep is interrupted it's because the executor
> wants us to shut down.
> Thread.currentThread().interrupt();
> }
> }
>
> When I inspect kSession in the debugger I can see the environment is
> properly set. I have tried digging down into the execute a bit but can't
> find any point at which the TransactionManager or EntityManagerFactory are
> used. As I said above I know Hibernate is set up correctly as well as
> Bitronix. I can see them working just fine in the logs and they definitely
> are hitting the database (and create tables for sessioninfo and
> workingmemory as they should). I just get nothing actually in the database
> stored, ever.
>
> Any help here is appreciated. It seems like it should work but it just
> doesn't.
>
> Thanks in advance,
>
> Jean-Philippe Steinmetz
>
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

[rules-users] Persistence in Drools 6

2014-05-22 Thread Steinmetz, Jean-Philippe
Hello All,

I am trying to set up persistence for a standalone Drools (6.0.1.Final)
application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via
Spring (4.0.3.RELEASE).

On the persistence side everything appears to be set up correctly. For my
Drools session I use a KieContainer to create a new stateful session using
an environment set up with the EntityManagerFactory and TransactionManager
set. The problem that I am experiencing however is that nothing is getting
persisted to the database. I have poured over the docs at least two dozen
times and searched the net for anything related.

Here is what my Spring context file looks like when creating the Drools
session...



























Since the application is standalone I execute fireAllRules on the session
at a regular interval (I use this instead of fireUntilHalt as it
dramatically reduces the CPU load on the machine). With each call I wrap it
in a transaction. Thus, the code looks as follows:

while (!Thread.currentThread().isInterrupted()) {
// Start a new transaction
UserTransaction utx = utx = (UserTransaction)new
InitialContext().lookup("java:comp/UserTransaction");
   utx.begin();

// Tick the session
kSession.fireAllRules();

// Close the transaction
utx.commit();

// Sleep so that other applications can use the CPU
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// When our sleep is interrupted it's because the executor
wants us to shut down.
Thread.currentThread().interrupt();
}
}

When I inspect kSession in the debugger I can see the environment is
properly set. I have tried digging down into the execute a bit but can't
find any point at which the TransactionManager or EntityManagerFactory are
used. As I said above I know Hibernate is set up correctly as well as
Bitronix. I can see them working just fine in the logs and they definitely
are hitting the database (and create tables for sessioninfo and
workingmemory as they should). I just get nothing actually in the database
stored, ever.

Any help here is appreciated. It seems like it should work but it just
doesn't.

Thanks in advance,

Jean-Philippe Steinmetz
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users