I too have been thinking about how to address this problem. While people may have performance concerns, I would like to try using Spring's AOP capabilities to proxy all(?) of my objects.
Ideally, we would modify the Hibernate code and somehow have it get instances of model beans from Spring's bean factory instead of using "new". I hope that Gavin and Rod are thinking about how this could be accomplished. :)
For the time being, I have come up with a solution that I think could be workable. Let's assume that you have your POJO model bean defined in Spring IoC with some AOP interceptors. I think you can use the delegate pattern...
Code:
public class SpringAopProxyModelBean
{
private static final ApplicationContext APPCTX;
static
{
APPCTX = null; // get a reference to the Spring AppContext
}
private ModelBean modelBean = APPCTX.getBean("modelBean");
public String getId()
{
return modelBean.getId();
}
public void setId(String id)
{
modelBean.setId(id);
}
}
L