[jboss-jira] [JBoss JIRA] Commented: (JBRULES-2332) Drools JPA- Spring Transactions

Pablo Nussembaum (JIRA) jira-events at lists.jboss.org
Wed Dec 16 14:34:30 EST 2009


    [ https://jira.jboss.org/jira/browse/JBRULES-2332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12500398#action_12500398 ] 

Pablo Nussembaum commented on JBRULES-2332:
-------------------------------------------

I committed an update to trunk that allows drools to participate in spring managed transactions. The changed project are: drools-persistence-jpa and drools-spring.
This is how a spring looks like:
<?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:drools="http://drools.org/schema/drools-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                        http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd">

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

	<bean id="sm1" class="org.drools.vsm.local.ServiceManagerLocalClient" />

	<drools:kbase id="kbase1" serviceManager="sm1">
		<drools:resource type="DRF" source="classpath:rules/VariablePersistenceStrategyProcess.rf" />
	</drools:kbase>

	<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>

	<bean id="jpaProcessKnowledgeProvider" class="org.drools.container.spring.beans.persistence.JPAKnowledgeServiceBean">
		<property name="kbase" ref="kbase1" />
		<property name="serviceManager" ref="sm1" />
		<property name="entityManagerFactory" ref="myEmf" />
		<property name="transactionManager" ref="txManager" />
		<property name="variablePersisters">
			<map>
				<entry key="javax.persistence.Entity" value="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
				<entry key="java.lang.String" value="org.plugtree.labs.variablepersistence.StringVariablePersister"/>
				<entry key="java.io.Serializable" value="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
			</map>
		</property>
	</bean>
</beans>


> Drools JPA- Spring Transactions
> -------------------------------
>
>                 Key: JBRULES-2332
>                 URL: https://jira.jboss.org/jira/browse/JBRULES-2332
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 5.0.1.FINAL
>         Environment: Java    (1.6)
> Spring framework (2.5.6)
> Hibernate  (3.3.2.GA)
> Drools   (5.0.1) Using Expert and Flow parts.
> Oracle  (11g)
>            Reporter: Pradeep Thomas
>            Assignee: Mark Proctor
>
> What we do
> We have a domain model. It is made up of a number of objects annotated with JPA annotations (for persistence) with Hibernate as the ORM provider. 
> The drools JPA persistence module is also made of java classes annotated for persistence.
> We're trying to create a stateful session and start a process. Process stops in a waiting state at some point. Then we want to persist the session together with the process state. Application needs to be able to load the session back into memory and continue with the process execution (by sending notify events).
> Issues
> First issue
> The first issue we faced was that the drools persistence module does not work out of box for Oracle.
> Cause: Table/column names too long, 
> Fix: This was sorted by overrides to the annotations in the drools-jpa source code.
> Current issue
> The issues that we are currently facing are related to transactions/JPA entity manager and persisting of Session/Process/Workitem etc.
> The expected transactional/persistence behaviour is
>        ------- Begin Transaction (triggered by Spring's transactional annotation that also creates the entity manager)
>    
>   1) Persist/Read domain entities from datasource
>   2) Persist/Read drools entities from same datasource
>        -------End Transaction (commit/rollback releases the entity manager)
> The expected behaviour is without the use of a distributed transaction manager (because we have a single datasource and no distributed transactions)
> It seems like the persistence module out of the box in drools-jpa relies on a Distributed transaction manager (DTM) and in the absence of one (configured by us) uses Bitronix (an built-in DTM)
> The use of Bitronix further complicates matters as its not related to the transaction/entity manager created by Spring and visibility of domain entities/drools entities have of each other.
> The way we would like to use drools persistence is:
> a) Entities (drools/domain) to be managed by the same entity manager (persisted/read) for both Domain model entities and Drools JPA entities.
> b) Participate in the same (RESOURCE_LOCAL) transaction (committed/rolled back)
> c) Eliminate the need for a DTM if there is a single datasource
> Question : is there anything we're doing is incorrect or is the described behaviour not available in the current version?
> Any advice would be appreciated.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list