Hi all,
I'm having problems when clearing the session for batch processing. I'm iterating over a long result set and doing something for each entity in it. If I clear the session every BATCH_SIZE entities, I get  "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" after the first batch. If I don't clear the session everything goes fine, except that memory is leaked. I think the problem has to do with second level cache because it started happening after I enabled this cache. Below is my configuration for the cache, and the code that is failing to execute.
Thank you in advance.
Cheers,
Carlos
Cache configuration:
Code:
 configuration.setProperty("hibernate.cache.provider_class",  
     "org.hibernate.cache.HashtableCacheProvider");
 configuration.setProperty(
     "hibernate.cache.use_query_cache", "true");
Batch processing:
Code:
        while (iterator.hasNext()) {
            Product product = iterator.next(); 
            index.store(product);
            if (++productCount % BATCH_SIZE == 0) {
                session.clear(); // <-- it works if I comment this line
            }
        }