marco-p wrote:
Hi, I need some light on this issue:
I'm using Hibernate 3.0.5 with two SessionFactory to connect to two different database. Every sessionFactory uses a different hibernate configuration file.
The databases has exactly the same structure but different data.
Since the tables I need are exactly the same, I'm using the same mapping documents.
The getter method for the object I need cycles the two source and returns the object given by the first answering source. Every source uses a simple session.get(); method to retrieve the object.
Everything works fine, but I noticed that when 2nd level cache is involved (ehcache), the first source always returns the object from the cache, even if the object is not in the corresponding db (it's in the other db!).
Some more info:
The sessionFactory are initialized in a static block and bound to a JNDI context, each with a different name, of course.
I'm using the sessionFactory.getCurrentSession() method to obtain a session.
I'm creating a single userTransaction for the whole request.
I've also tried to disable the cache for the object and everything works, without the problem described above.
Can someone shed some light on this? What I'm missing?
TIA
It sounds like you have both SessionFactory objects pointing to the same cache. I don't believe that the SessionFactory keeps track of whats in cache, but just checks the cache implementation when necessary and returns the object if it's found. If SF1 puts something into cache, it's logical that SF2 will find it when it looks in cache. There's no database dependency on the cache.