Announcement Announcement Module
Collapse
No announcement yet.
Hibernate TransactionProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate TransactionProxyFactoryBean

    Hi,

    I'm using Spring's TransactionProxyFactoryBean to manage a Hibernate DAO in the manner suggested in the reference documentation:

    Code:
    	<bean id="myDao" class="com.example.MyDaoImpl">
    		<property name="sessionFactory"><ref local="sessionFactory"/></property>
    	</bean>
    
    	<bean id="myProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager"><ref local="transactionManager"/></property>
    		<property name="target"><ref local="myDao"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>				
    				<prop key="update*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
    My understanding is that this will wrap the DAO methods in read/write or read-only transactions depending on whether the method name matches "update*" or "get*".

    Does this mean that each time a method matching "update*" is called it will be wrapped in a separate transaction?

    What if (in the application code), I want to call two "update*" DAO methods and want them to be wrapped in a single transaction, i.e. I don't want the first one to commit if the second fails?

    Is there any way to achieve this apart from writing another "update*" DAO method which calls the latter two?

    Perhaps the question which I'm really asking is simply "When do transactions get committed?"

    Thanks in advance,
    DM
    Last edited by domurtag; Oct 18th, 2006, 01:07 PM.

  • #2
    Apply transactions on service

    Hi domurtag,

    Originally posted by domurtag View Post
    Is there any way to achieve this apart from writing another "update*" DAO method which calls the latter two?
    That is one of the reasons it is recommended that you apply transactions at the service level. If so, you can reuse your DAOs in different transactional settings.

    So in your case, if you have a "service" that requires updates via two different DAOs, you would apply the transaction at the service level.

    Note the Petstore sample application. In it, there is a service interface, Petstore, and the implementation class, PetStoreImpl, uses various DAOs to accomplish its work. You can also see that the non-proxied DAOs are injected into the service, and the transactions are defined on the service's methods.

    -Arthur Loder

    Comment


    • #3
      Thanks for the reply Arthur!

      So basically what you're saying is that commit is called after each method of the target is called? Of course, Spring doesn't know/care whether the target is a DAO, a service, or anything else....

      Comment

      Working...
      X