<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:kie="http://drools.org/schema/kie-spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">

  <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:tcp://localhost/DroolsFlow"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
  </bean>

  <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="ds"/>
    <property name="persistenceUnitName" value="org.drools.persistence.jpa.local"/>
  </bean>

  <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="myEmf"/>
  </bean>

  <kie:kstore id="kstore1"/>

  <kie:kmodule id="var_persistence">
    <kie:kbase name="drl_persistence" packages="drl_persistence">
      <kie:ksession name="jpaSingleSessionCommandService2">
        <kie:configuration>
          <kie:jpa-persistence>
            <kie:transaction-manager ref="txManager"/>
            <kie:entity-manager-factory ref="myEmf"/>
          </kie:jpa-persistence>
        </kie:configuration>
      </kie:ksession>
    </kie:kbase>

    <kie:kbase name="drl_persistence_rb" packages="drl_persistence_rb">
      <kie:ksession name="jpaSingleSessionCommandServiceRollback">
        <kie:configuration>
          <kie:jpa-persistence>
            <kie:transaction-manager ref="txManager"/>
            <kie:entity-manager-factory ref="myEmf"/>
          </kie:jpa-persistence>
        </kie:configuration>
      </kie:ksession>
    </kie:kbase>
  </kie:kmodule>

  <!-- additions for environment -->
  <bean id="globals" class="org.drools.core.base.MapGlobalResolver"/>

  <kie:environment id="env">    
    <kie:transaction-manager ref="txManager"/>
    <kie:entity-manager-factory ref="myEmf"/>
    <kie:globals ref="globals"/>

    <kie:object-marshalling-strategies>
      <kie:jpa-placeholder-resolver-strategy/>
      <kie:serializable-placeholder-resolver-strategy strategy-acceptor-ref="dacceptor"/>
    </kie:object-marshalling-strategies>
  </kie:environment>

  <kie:environment id="env2">    
    <kie:transaction-manager ref="txManager"/>
    <kie:entity-manager-factory ref="myEmf"/>
    <kie:globals>
      <bean class="org.drools.core.base.MapGlobalResolver"/>
    </kie:globals>

    <kie:object-marshalling-strategies>
      <kie:serializable-placeholder-resolver-strategy strategy-acceptor-ref="dacceptor"/>
    </kie:object-marshalling-strategies>
  </kie:environment>

  <bean id="dacceptor" class="org.drools.core.marshalling.impl.ClassObjectMarshallingStrategyAcceptor">
    <constructor-arg>
      <list>
        <value>*.*</value>
      </list>
    </constructor-arg>
  </bean>
  <!-- end additions for environment -->

  <bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>

</beans>
