I am porting a legacy application to hibernate 5 and I'm having trouble with the login phase. Here's how it works (I can't change that):
I currently create one instance of sessionFactory per connected user, but I'm worried that this will impact performance. Is there a better way to do this?
Thanks
hibernate. HibernateException: HHH000469: The ClassLoaderService can not be reused.
You would need one SessionFactory object per database using a separate configuration file. So, if you are using multiple databases, then you would have to create multiple SessionFactory objects.
Sessionfactory will create and manage the sessions. If you have say, 4 datasources/databases, then you must create 4 session factory instances. sessionfactory is an immutable object and it will be created as a singleton while the server initializes itself.
Session factory is long live multithreaded object. Usually one session factory should be created for one database. When you have multiple databases in your application you should create multiple SessionFactory object.
Hibernate Multitenancy with "Separate database" strategy would work even if you are actually connecting to the same database but different credentials. MultiTenantConnectionProvider must be specified to return connection with right username and password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With