TouchingAfterReturningAdvice offers an alternative to the open session in view pattern in that it touches configurable properties on the return value of method invocations. This advice is available in the Spring Modules sandbox.
If the return value is an instance of java.util.Collection or Object[] all its elements will be touched with the configured properties. If no properties have been specified collections will still be iterated over.
An example:
The service:
The domain class:Code:public interface CustomerService { public Collection findAllCustomers(); }
The Spring config:Code:public class Customer { private Collection pendingOrders = null; // this property is configured for lazy loading. public Collection getPendingOrders() { return this.pendingOrders; } private Collection completedOrders = null; // this property is configured for lazy loading. public Collection getCompletedOrders() { return this.completedOrders; } }
Code:<bean id="customerService" parent="transactionedBean"> <property name="target"> <bean class="....DefaultCustomerService" autowire="byType"/> </property> <property name="postInterceptors"> <list> <bean class="....NameMatchMethodPointcutAdvisor"> <property name="mappedNames"> <value>findAllCustomers</value> </property> <property name="advice"> <bean class="org.springmodules.aop.framework.TouchingAfterReturningAdvice"> <property name="properties"> <list> <value>pendingOrders</value> <map> <entry key="completedOrders"> <list> <value>products</value> </list> </entry> </map> </list> </property> </bean> </property> </bean> </list> </property> </bean>


