[rules-users] Exception using persistence

tolitius webakaunt at gmail.com
Tue Jun 1 23:57:16 EDT 2010


There is no need to use JTA, unless you have a reason for it. You can use a
RESOURCE_LOCAL (non XA transaction):

PERSISTENCE.XML:

	<persistence-unit name="workflow.framework.persistence.unit"
		                transaction-type="RESOURCE_LOCAL">

		<provider>org.hibernate.ejb.HibernatePersistence</provider>
 
                ... ... ...
	</persistence-unit>

SPRING CONFIG:

        <bean id="abstractKnowledgeProvider"
                
class="org.drools.container.spring.beans.persistence.JPAKnowledgeServiceBean"
abstract="true">

              <property name="entityManagerFactory"
ref="entityManagerFactory" />
              <property name="transactionManager" ref="txManager" />
              <property name="variablePersisters">
                        <util:map>
                                <entry key="javax.persistence.Entity"
                                         
value="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
                                <entry key="java.lang.String"
                                         
value="some.other.package.drools.variablepersistence.StringVariablePersister"/>
                                <entry key="java.io.Serializable"
                                         
value="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
                        </util:map>
               </property>
        </bean>

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

        <bean id="entityManagerFactory"
                
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="persistenceUnitName"
value="your.persistence.unit" />
                <property name="dataSource" ref="datasource" />
                <property name="jpaProperties">
                        <props>
                            <prop
key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
                            <prop
key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
                            <prop
key="hibernate.show_sql">${hibernate.show_sql}</prop>
                            <prop
key="hibernate.dialect">${hibernate.dialect}</prop>
                            <prop
key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                        </props>
                </property>
        </bean>

        <bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
        <bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

        <drools:connection id="connection1" type="local" />
        <drools:execution-node id="node1" connection="connection1" />


If the app you are building is any serious, you will of course need some
tx:advices & aop:configs to spice it up, but that is another discussion... (
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
)

/Anatoly
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Exception-using-persistence-tp856774p863641.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list