Hi all,
I tried using the following, pretty standard, configuration to open my hibernate session and declaratively demarcate transactions:
Attempting to use this code resulted in HibernateTransactionManager not opening a Session unless the method name in my service object matched "save*" or "del*".Code:<bean id="txProxyTemplate" abstract="true" singleton="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="hibernateTransactionManager"/> </property> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <!---- NOTICE THE FOLLOWING LINE ----> <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop> </props> </property> </bean> <bean id="aService" parent="txProxyTemplate"> <property name="target"> <bean class="a.service.class"> <property name="aDao"> <ref bean="myHibernateDao"/> </property> </bean> </property> </bean>
Now, I understand than the hibernate transaction manager opens a session and creates a transaction according to the transactionAttributes but it took be quite a while to make the inverse realization that since PROPAGATION_SUPPORTS implies that a transaction will not be started (unless that is there is a surrounding tx which is not my case) the hibernate session won't be opened either.
So, what is one supposed to do:
- 1. avoid PROPAGATION_SUPPORTS?
2. use a HibernateInterceptor as well (using the postInterceptors attribute of the TransactionProxyFactoryBean)?
My opinion is that the session should be opened by the TransactionProxyFactoryBean even when using PROPAGATION_SUPPORTS.
In any case I think this point could be made somewhere in the documentation, ie, that the session won't be opened unless a transaction is started, even if the method name is matched against the transactionAttributes.
Best regards,
Giorgos


Reply With Quote
