
Originally Posted by
bpolka
There are alternatives to it though. I have been playing around with AspectJ to enable transparent collection touching and current version verification, but have not had much time to finish anything.
Interesting idea... Just read through a bit of AspectJ documentation to see how it might work. All I was able to imagine so far was an aspect for reconnecting an entity whenever lazy instantiation was required. Since I can't even claim to be an AspectJ newbie, that might be very naive on my behalf.... Something like:
Code:
aspect ReconnectWhenNeeded {
pointcut getCollection(Entity entity):
(target(entity) &&
(call(List com.blah.domain.*.get*()) ||
call(Set com.blah.domain.*.get*()) ||
call(Map com.blah.domain.*.get*())));
before(Entity entity): getCollection(entity){
// somehow transactionalize this call and associate entity with current session
// equivalent of this.getHibernateTemplate().lock(entity, LockMode.NONE) in a DAO
}
}
Is this anything close to what you had in mind?
Can AspectJ aspects be wired with Spring?
I'm not sure how you'd use spring-managed hibernate entities (i.e. DependencyInjectionInterceptorFactoryBean) to enable on-demand collection touching... short of giving the entity a reference to a service object, and then starting every public getPersistentCollection method with a call to the service.reconnect(entity), which gets the DAO to reconnect the entity. Sound a bit convoluted! But if anybody has a suggestion here, I'd be interested in exploring it.
Best regards,
Assaf