Hello All
I have two applications which use same object model and I need to use lazy loading in one application and don't use it in another. I need to implement this functionality with minimal changes in code and I don't like to generate different mappings for different applications(I do so now).
I've read here about following solution:
Quote:
If you like to disable/enable some setting globally, you might rebuild the SessionFactory after modifying the metadata from the Configuration programatically. This is easier than it sounds, get all PersistentClass objects from Configuration (the API), loop over all collections and setLazy(true). Then, build a new SessionFactory from this Configuration.
and tried to ipmpement it:
Code:
Configuration cfg = ConnectionFactory.createConfiguration(theProperties);
cfg.configure();
// Disable lazy loadings
for(Iterator iterator = cfg.getCollectionMappings(); iterator.hasNext();)
{
Collection collection = (Collection)iterator.next();
collection.setLazy(false);
}
ConnectionFactory.sessionFactory = cfg.buildSessionFactory();
and it doesn't work. My questions are:
1. what am I doinng wrong?
2. how can I implement this functionality in another way? Eager fetching is not suitable for me because I have more then one collections in my objects.[/i]