An instance of SessionFactory is perfectly thread safe. That's not the issue. The problem is that the buildSessionFactory method on the Configuraiton class is NOT, even when called on DISTINCT Configuration instances!! This seems to be a pretty signifcant bug...
fyi, there are many reasons two have more than one SessionFactory instance. For example, you might be accessing more than one DB, and want to map the same object hierarchy to both DBs. The only way to do this in Hibernate is with distinct session factories. Another example is mapping the same object to two different tables in the same DB, as I do in my app. For have example, I have a CLIENT and a CLIEN_HIST table, which are exactly the same. Every time a client is updated a new row is inserted into the CLIENT_HIST table ( for audit trail purposes ), as well as a row in the CLIENT table is updated. That way, when you're interested in the latest client info, you don't have to search through the milllions of rows in the CLIENT_HIST table, but simply look in the much smaller CLIENT table.
Anyway, there are other reasons as well...
|