PDA

View Full Version : jcr + jackrabbit - LocalTransactionManager configuration



derek
Jun 29th, 2006, 09:47 AM
Going through the JCR chapter in the reference manual.

Not quite understanding the necessary configuration for a LocalTransactionManager.

My test program was working without transactions. Then added this to my config:


<bean id="jcrTransactionManager" class="org.springmodules.jcr.jackrabbit.LocalTransactionM anager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

and got:


java.lang.IllegalStateException: No session bound to thread, and configuration does not allow creation of non-transactional one here


Haven't quite understood the bit about ProviderManagers. The example doesn't work as JcrTemplate doesn't seem to have a providerManager property. Looking through the source, shouldn't that rather be set on the JcrSessionFactory using setSessionHolderProviderManager(...) ?

However, I don't quite understand what this ProviderManager does. Whether it is required. And if so, what I need to put into META-INF/services

The manual does say "JCR support contains (quite a lot of) classes to make this issue as painful as possible." but I'm sure that must be a typo :)

Appreciate any help.

Regards,
D.

Costin Leau
Jun 29th, 2006, 10:09 AM
I just realized that the JCR documentation is outdated. I'll make sure to fix this in the upcoming 0.5 release.
With ProviderManager simply don't bother - the defaults are good enough for most cases including jackrabbit support.
As for the transaction manager - once declared you have to just plug it inside Spring infrastructure:


<!-- transaction proxy for Jcr services/facades -->
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="proxyTargetClass" value="true"/>
<property name="transactionManager" ref="jcrTransactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
</props>
</property>
</bean>

<bean id="jcrService" parent="txProxyTemplate">
<property name="target">
<bean class="org.springmodules.examples.jcr.JcrService">
<property name="template" ref="jcrTemplate"/>
</bean>
</property>
</bean>

<bean id="jcrTransactionManager"
class="org.springmodules.jcr.jackrabbit.LocalTransactionM anager">
<property name="sessionFactory" ref="jcrSessionFactory"/>
</bean>



The manual does say "JCR support contains (quite a lot of) classes to make this issue as painful as possible." but I'm sure that must be a typo :)
Indeed :D. Thanks for spotting this out.

I'll update both the docs and the examples these days - they should be up and running sometime next week. Sorry for the inconvenience - I completely forgot about them as the tests passed.

Costin Leau
Jun 29th, 2006, 10:19 AM
You can follow the issue here: http://opensource.atlassian.com/projects/spring/browse/MOD-160.

Thanks again for reporting.

derek
Jun 29th, 2006, 10:35 AM
Hi Costin,

Thanks for the swift reply. Has done the trick.

D.