JBoss Community

Re: Drools, Spring integration and JTA in container

created by Alex Manly in jBPM - View the full discussion

I have this same problem.

 

In the spring config I create the Transaction manager as follows:

 

 

    <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/rd-domain-pu" />

 

    <tx:jta-transaction-manager />

 

 

This creates a transaction manager with the type:

 

org.springframework.transaction.jta.JtaTransactionManager

 

 

My drools spring config is this:

 

    <drools:kbase id="kbase1">

        <drools:resources>

            <drools:resource id="cloneFlow" type="DRF" source="classpath:Clone.rf"/>

            <drools:resource id="approvalFlow" type="DRF" source="classpath:Approval.rf"/>

          </drools:resources>

 

        <drools:configuration>

            <drools:mbeans enabled="true" />

            <drools:event-processing-mode mode="STREAM" />

        </drools:configuration>

    </drools:kbase>

 

    <drools:ksession id="jpaSingleSessionCommandService" type="stateful" kbase="kbase1" name="stateful-session">

        <drools:configuration>           

            <drools:jpa-persistence>

                <drools:transaction-manager ref="transactionManager" />

                <drools:entity-manager-factory ref="entityManagerFactory" />

                <drools:variable-persisters>

                    <drools:persister for-class="javax.persistence.Entity" implementation="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>

                    <drools:persister for-class="java.io.Serializable" implementation="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>

                </drools:variable-persisters>

            </drools:jpa-persistence>

            <drools:work-item-handlers>

                <drools:work-item-handler name="Human Task" ref="humanTaskHandler"/>

            </drools:work-item-handlers>

            <drools:keep-reference enabled="true" />

            <drools:clock-type type="REALTIME" />

        </drools:configuration>

        <drools:script>

            <drools:start-process process-id="1"/>

            <drools:fire-all-rules/>

        </drools:script>

    </drools:ksession>

 

 

No when the spring context is loaded I get the same error and the problem is the initTransactionManager method in SingleSessionComand:

 

The problem is the class does start with "org.springframework" (in the first if statement.  But the class does not contain "jpa" in the second if statement.  Which means the line comment: //configure spring for JPA and distributed transactions

 

public void initTransactionManager(Environment env) {

        Object tm = env.get( EnvironmentName.TRANSACTION_MANAGER );

        if ( tm != null && tm.getClass().getName().startsWith( "org.springframework" ) ) {

            try {

                Class<?> cls = Class.forName( "org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager" );

                Constructor<?> con = cls.getConstructors()[0];

                this.txm = (TransactionManager) con.newInstance( tm );

                logger.debug( "Instantiating  DroolsSpringTransactionManager" );

 

                if ( tm.getClass().getName().toLowerCase().contains( "jpa" ) ) {

                    // configure spring for JPA and local transactions

                    cls = Class.forName( "org.drools.container.spring.beans.persistence.DroolsSpringJpaManager" );

                    con = cls.getConstructors()[0];

                    this.jpm =  ( JpaManager) con.newInstance( new Object[] { this.env } );

                } else {

                    // configure spring for JPA and distributed transactions

                }

            } catch ( Exception e ) {

                logger.warn( "Could not instatiate DroolsSpringTransactionManager" );

                throw new RuntimeException( "Could not instatiate org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager", e );

            }

        } else {

            logger.debug( "Instantiating  JtaTransactionManager" );

            this.txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ),

                                                  env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ),

                                                  tm );

            this.jpm = new DefaultJpaManager(this.env);

        }

    }

 

 

Does anyone from Drools development know when the code will support a  "org.springframework.transaction.jta.JtaTransactionManager" class?

 

Thanks in advance

Reply to this message by going to Community

Start a new discussion in jBPM at Community