Has anyone tried implementing a single SessionFactory with multiple data sources?
Here's my use case:
When clients log on, they are associated with one of several databases. Each of these databases has exactly the same structure, but obviously can contain different data. Any reads or updates made will be to the single database. There is no requirement to update multiple databases in the same transaction.
In JDBC terms, I need multiple DataSources. Since the structure of each of the database is identical, there should only be a single SessionFactory.
My understanding is that this should work if only the primary (transaction-scoped ) cache is used, because by definition each will apply to a single transaction. It could also work for the second level cache if this contains read only data, because even if Hibernate only has one second level cache per session factory, the read only data for each of the databases should be the same.
Are there any other gotchas that I am missing, restrictions I should apply to allow this configuration to work reliably?
|