-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Stephen Duncan Jr opened SPR-1695 and commented
If I specify a ProxyFactoryBean with a targetSource of type LazyInitTargetSource which targets a LocalSessionFactoryBean, the underlying Hibernate SessionFactory is created anyway.
The problem is that to create the proxy, the LazyInitTargetSource must determine the type of the object is must proxy. So it calls getObjectType on the bean. Because the bean is a FactoryBean, it must instantiate the FactoryBean to call getObjectType on it. This, however, causes the SessionFactory to be created, because that is done in the afterPropertiesSet method.
One solution would be to modify LocalSessionFactoryBean to delay instantiation of the SessionFactory until the getObject method is called.
Another might be to first attempt to call getObjectType on the factory before setting any properties. That way if the value is known beforehand (not dynamically), the rest of the methods wouldn't be called.
The last solution that occurs to me is to provide another way to specify the object type. Such as having it be a property you could set on the LazyInitTargetSource. This would prevent instantiation of the Factory even, and therefore would seem to honor the intentions of not instantiating what you're proxying better.
Affects: 1.2.6